1
22
23 package com.liferay.portal.captcha;
24
25 import com.liferay.portal.struts.ActionConstants;
26 import com.liferay.portal.util.PropsFiles;
27 import com.liferay.portal.util.WebKeys;
28 import com.liferay.util.ExtPropertiesLoader;
29
30 import java.util.Properties;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import javax.servlet.http.HttpSession;
35 import javax.servlet.jsp.PageContext;
36
37 import nl.captcha.servlet.CaptchaProducer;
38 import nl.captcha.util.Helper;
39
40 import org.apache.struts.action.Action;
41 import org.apache.struts.action.ActionForm;
42 import org.apache.struts.action.ActionForward;
43 import org.apache.struts.action.ActionMapping;
44
45
51 public class CaptchaPortalAction extends Action {
52
53 public CaptchaPortalAction() {
54 Properties props = ExtPropertiesLoader.getInstance(
55 PropsFiles.CAPTCHA).getProperties();
56
57 _producer = (CaptchaProducer)Helper.ThingFactory.loadImpl(
58 Helper.ThingFactory.CPROD, props);
59 }
60
61 public ActionForward execute(
62 ActionMapping mapping, ActionForm form, HttpServletRequest req,
63 HttpServletResponse res)
64 throws Exception {
65
66 try {
67 HttpSession ses = req.getSession();
68
69 String captchaText = _producer.createText();
70
71 ses.setAttribute(WebKeys.CAPTCHA_TEXT, captchaText);
72
73 _producer.createImage(res.getOutputStream(), captchaText);
74
75 return null;
76 }
77 catch (Exception e) {
78 req.setAttribute(PageContext.EXCEPTION, e);
79
80 return mapping.findForward(ActionConstants.COMMON_ERROR);
81 }
82 }
83
84 private CaptchaProducer _producer;
85
86 }