gatein SVN: r5524 - in portal/trunk: webui/portal/src/main/java/org/exoplatform/portal/webui and 1 other directory.
by do-not-reply@jboss.org
Author: thomas.heute(a)jboss.com
Date: 2010-12-09 07:50:19 -0500 (Thu, 09 Dec 2010)
New Revision: 5524
Modified:
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
Log:
GTNPORTAL-1721: Captcha doesn't change after successful registration
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java 2010-12-09 12:24:59 UTC (rev 5523)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java 2010-12-09 12:50:19 UTC (rev 5524)
@@ -67,18 +67,18 @@
{
PortletSession session = req.getPortletSession();
Captcha captcha;
- if (session.getAttribute(NAME, PortletSession.APPLICATION_SCOPE) == null)
+ if (session.getAttribute(NAME) == null)
{
captcha = new Captcha.Builder(_width, _height).addText().gimp().addNoise().addBackground().build();
- session.setAttribute(NAME, captcha, PortletSession.APPLICATION_SCOPE);
+ session.setAttribute(NAME, captcha);
writeImage(resp, captcha.getImage());
return;
}
- captcha = (Captcha)session.getAttribute(NAME, PortletSession.APPLICATION_SCOPE);
+ captcha = (Captcha)session.getAttribute(NAME);
writeImage(resp, captcha.getImage());
}
Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java 2010-12-09 12:24:59 UTC (rev 5523)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java 2010-12-09 12:50:19 UTC (rev 5524)
@@ -19,7 +19,6 @@
package org.exoplatform.account.webui.component;
-import org.exoplatform.portal.application.PortalRequestContext;
import org.exoplatform.portal.webui.CaptchaValidator;
import org.exoplatform.portal.webui.UICaptcha;
import org.exoplatform.portal.webui.util.Util;
@@ -27,6 +26,7 @@
import org.exoplatform.services.organization.UserHandler;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.portlet.PortletRequestContext;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.core.UIApplication;
@@ -99,10 +99,11 @@
if(popupMessages.getWarnings().size() > 0 || popupMessages.getErrors().size() > 0)
{
//Invalidate the capcha
- PortalRequestContext prContext = Util.getPortalRequestContext();
- HttpServletRequest request = prContext.getRequest();
- HttpSession session = request.getSession();
- session.removeAttribute(Captcha.NAME);
+ if (context instanceof PortletRequestContext)
+ {
+ PortletRequestContext prc = (PortletRequestContext)context;
+ prc.getRequest().getPortletSession().removeAttribute(Captcha.NAME);
+ }
context.addUIComponentToUpdateByAjax(getChild(UIRegisterInputSet.class));
}
}
@@ -112,9 +113,6 @@
@Override
public void execute(Event<UIRegisterForm> event) throws Exception
{
- // Invalidate the captcha image
- PortalRequestContext prContext = Util.getPortalRequestContext();
-
UIRegisterForm registerForm = event.getSource();
OrganizationService orgService = registerForm.getApplicationComponent(OrganizationService.class);
UserHandler userHandler = orgService.getUserHandler();
@@ -127,9 +125,13 @@
UIApplication uiApp = context.getUIApplication();
uiApp.addMessage(new ApplicationMessage("UIRegisterForm.registerWithSuccess.message", null));
}
- HttpServletRequest request = prContext.getRequest();
- HttpSession session = request.getSession();
- session.removeAttribute(Captcha.NAME);
+
+ //Invalidate the capcha
+ if (context instanceof PortletRequestContext)
+ {
+ PortletRequestContext prc = (PortletRequestContext)context;
+ prc.getRequest().getPortletSession().removeAttribute(Captcha.NAME);
+ }
}
}
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2010-12-09 12:24:59 UTC (rev 5523)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2010-12-09 12:50:19 UTC (rev 5524)
@@ -49,7 +49,7 @@
PortletRequest req = ctx.getRequest();
PortletSession session = req.getPortletSession();
- Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME, PortletSession.APPLICATION_SCOPE);
+ Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
if ((captcha != null) && (captcha.isCorrect((String) uiInput.getValue())))
{
Modified: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java 2010-12-09 12:24:59 UTC (rev 5523)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java 2010-12-09 12:50:19 UTC (rev 5524)
@@ -22,6 +22,8 @@
******************************************************************************/
package org.exoplatform.portal.webui;
+import java.util.Calendar;
+
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.form.UIFormStringInput;
@@ -50,9 +52,9 @@
// context.getPortalContextPath() + "/captcha?v=" + Calendar.getInstance().getTimeInMillis()
+ String random = "&v=" + Calendar.getInstance().getTimeInMillis();
-
- context.getWriter().write("<div id='" + getId() + "'><img src=\"" + url.toString() + "\" /><br/>");
+ context.getWriter().write("<div id='" + getId() + "'><img src=\"" + url.toString() + random + "\" /><br/>");
super.processRender(context);
context.getWriter().write("</div>");
}