You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ja...@apache.org on 2012/05/15 15:31:15 UTC
svn commit: r1338700 - in /ofbiz/trunk:
framework/common/src/org/ofbiz/common/
specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/
specialpurpose/ecommerce/webapp/ecommerce/customer/
specialpurpose/myportal/script/org/ofbiz/myportal/ specialp...
Author: jacopoc
Date: Tue May 15 13:31:15 2012
New Revision: 1338700
URL: http://svn.apache.org/viewvc?rev=1338700&view=rev
Log:
Completed refactoring/cleanup of captcha implementation that now supports screens with more than one captcha in them.
Removed:
ofbiz/trunk/framework/common/src/org/ofbiz/common/Captcha.java
ofbiz/trunk/specialpurpose/myportal/widget/MyPortalForms.xml
Modified:
ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java
ofbiz/trunk/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl
ofbiz/trunk/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml
ofbiz/trunk/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml
ofbiz/trunk/specialpurpose/myportal/widget/CommonScreens.xml
ofbiz/trunk/specialpurpose/myportal/widget/RegisterPerson.ftl
Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java (original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonEvents.java Tue May 15 13:31:15 2012
@@ -28,6 +28,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -379,11 +380,12 @@ public class CommonEvents {
return "success";
}
- public static String getCaptcha(HttpServletRequest request,HttpServletResponse response) {
+ public static String getCaptcha(HttpServletRequest request, HttpServletResponse response) {
try {
final String captchaSizeConfigName = StringUtils.defaultIfEmpty(request.getParameter("captchaSize"), "default");
final String captchaSizeConfig = UtilProperties.getPropertyValue("captcha.properties", "captcha." + captchaSizeConfigName);
final String[] captchaSizeConfigs = captchaSizeConfig.split("\\|");
+ final String captchaCodeId = StringUtils.defaultIfEmpty(request.getParameter("captchaCodeId"), ""); // this is used to uniquely identify in the user session the attribute where the captcha code for the last captcha for the form is stored
final int fontSize = Integer.parseInt(captchaSizeConfigs[0]);
final int height = Integer.parseInt(captchaSizeConfigs[1]);
@@ -463,7 +465,12 @@ public class CommonEvents {
response.setContentType("image/jpeg");
ImageIO.write(bufferedImage, "jpg", response.getOutputStream());
HttpSession session = request.getSession();
- session.setAttribute("_CAPTCHA_CODE_", captchaCode);
+ Map captchaCodeMap = (Map)session.getAttribute("_CAPTCHA_CODE_");
+ if (captchaCodeMap == null) {
+ captchaCodeMap = new HashMap();
+ session.setAttribute("_CAPTCHA_CODE_", captchaCodeMap);
+ }
+ captchaCodeMap.put(captchaCodeId, captchaCode);
} catch (Exception ioe) {
Debug.logError(ioe.getMessage(), module);
}
Modified: ofbiz/trunk/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml Tue May 15 13:31:15 2012
@@ -1287,7 +1287,7 @@ under the License.
</else>
</if-empty>
<call-object-method obj-field="parameters.captcha" method-name="toLowerCase" ret-field="submittedCaptcha"/>
- <script>groovy: context.actualCaptcha = request.getSession().getAttribute("_CAPTCHA_CODE_")?.toLowerCase()</script>
+ <script>groovy: context.actualCaptcha = request.getSession().getAttribute("_CAPTCHA_CODE_")?.get("captchaImage")?.toLowerCase()</script>
<if-compare-field operator="not-equals" field="submittedCaptcha" to-field="actualCaptcha">
<add-error><fail-property resource="MyPortalUiLabels" property="MyPortalCaptchaMissingError"/></add-error>
</if-compare-field>
Modified: ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl (original)
+++ ofbiz/trunk/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl Tue May 15 13:31:15 2012
@@ -23,11 +23,11 @@ under the License.
</div>
<script type="text/javascript" language="JavaScript">
<!--
- function reloadCaptcha() {
- var captchaUri = "<@o...@ofbizUrl>";
+ function reloadCaptcha(fieldName) {
+ var captchaUri = "<@ofbizUrl>captcha.jpg?captchaCodeId=" + fieldName + "&unique=_PLACEHOLDER_</...@ofbizUrl>";
var unique = Date.now();
captchaUri = captchaUri.replace("_PLACEHOLDER_", unique);
- document.getElementById("captchaImage").src = captchaUri;
+ document.getElementById(fieldName).src = captchaUri;
}
//-->
</script>
@@ -63,7 +63,7 @@ under the License.
</tr>
<tr>
<td class="label">${uiLabelMap.CommonCaptchaCode}</td>
- <td><div><img id="captchaImage" src="<@o...@ofbizUrl>" alt="" /></div><a href="javascript:reloadCaptcha();">${uiLabelMap.CommonReloadCaptchaCode}</a></td>
+ <td><div><img id="captchaImage" src="<@o...@ofbizUrl>" alt="" /></div><a href="javascript:reloadCaptcha('captchaImage');">${uiLabelMap.CommonReloadCaptchaCode}</a></td>
</tr>
<tr>
<td class="label">${uiLabelMap.CommonVerifyCaptchaCode}</td>
Modified: ofbiz/trunk/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml (original)
+++ ofbiz/trunk/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml Tue May 15 13:31:15 2012
@@ -23,9 +23,6 @@ under the License.
<simple-method method-name="createRegister"
short-description="Create person when new register" login-required="false">
- <call-bsh><![CDATA[
- org.ofbiz.common.Captcha.getCodeCaptcha(request,response);
- ]]></call-bsh>
<if-empty field="parameters.firstName"><property-to-field field="errorMessage" resource="MyPortalUiLabels" property="MyPortalFirstNameMissing"/><field-to-list field="errorMessage" list="error_list"/></if-empty>
<if-empty field="parameters.lastName"><property-to-field field="errorMessage" resource="MyPortalUiLabels" property="MyPortalLastNameMissing"/><field-to-list field="errorMessage" list="error_list"/></if-empty>
<if-empty field="parameters.USERNAME"><property-to-field field="errorMessage" resource="PartyUiLabels" property="PartyUserNameMissing"/><field-to-list field="errorMessage" list="error_list"/></if-empty>
@@ -47,7 +44,7 @@ under the License.
<call-object-method obj-field="parameters.PASSWORD" method-name="toLowerCase" ret-field="parameters.PASSWORD"/>
<call-object-method obj-field="parameters.CONFIRM_PASSWORD" method-name="toLowerCase" ret-field="parameters.CONFIRM_PASSWORD"/>
<call-object-method obj-field="parameters.captcha" method-name="toLowerCase" ret-field="submittedCaptcha"/>
- <script>groovy: context.actualCaptcha = request.getSession().getAttribute("_CAPTCHA_CODE_")?.toLowerCase()</script>
+ <script>groovy: context.actualCaptcha = request.getSession().getAttribute("_CAPTCHA_CODE_")?.get("captchaImage")?.toLowerCase()</script>
<if-compare field="parameters.PASSWORD" value="${parameters.CONFIRM_PASSWORD}" operator="equals">
<if-compare-field operator="equals" field="submittedCaptcha" to-field="actualCaptcha">
Modified: ofbiz/trunk/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml (original)
+++ ofbiz/trunk/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml Tue May 15 13:31:15 2012
@@ -38,7 +38,6 @@
</request-map>
<request-map uri="newRegisterLogin">
<security https="true" auth="false"/>
- <event type="java" invoke="getCodeCaptcha" path="org.ofbiz.common.Captcha"/>
<response name="success" type="view" value="newRegisterLogin"/>
</request-map>
<request-map uri="createRegister">
Modified: ofbiz/trunk/specialpurpose/myportal/widget/CommonScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/myportal/widget/CommonScreens.xml?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/myportal/widget/CommonScreens.xml (original)
+++ ofbiz/trunk/specialpurpose/myportal/widget/CommonScreens.xml Tue May 15 13:31:15 2012
@@ -156,12 +156,7 @@ under the License.
<fail-widgets>
<screenlet title="${uiLabelMap.MyPortalNewRegistration}">
<section>
- <actions>
- <set field="fileName" from-field="parameters.fileName"/>
- <set field="idKey" from-field="parameters.ID_KEY"/>
- </actions>
<widgets>
- <!--<include-form name="RegisterPerson" location="component://myportal/widget/MyPortalForms.xml"/> -->
<platform-specific>
<html><html-template location="component://myportal/widget/RegisterPerson.ftl"/></html>
</platform-specific>
Modified: ofbiz/trunk/specialpurpose/myportal/widget/RegisterPerson.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/myportal/widget/RegisterPerson.ftl?rev=1338700&r1=1338699&r2=1338700&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/myportal/widget/RegisterPerson.ftl (original)
+++ ofbiz/trunk/specialpurpose/myportal/widget/RegisterPerson.ftl Tue May 15 13:31:15 2012
@@ -96,27 +96,22 @@ under the License.
</tr>
<tr>
<td class="label"> Code Captcha </td>
- <td><div><img id="captchaImage" src="<@o...@ofbizUrl>" alt="" /></div></td>
+ <td><div><img id="captchaImage" src="<@o...@ofbizUrl>" alt="" /></div></td>
</tr>
<script type="text/javascript" language="JavaScript">
<!--
- function reloadCaptcha() {
- var captchaUri = "<@o...@ofbizUrl>";
+ function reloadCaptcha(fieldName) {
+ var captchaUri = "<@ofbizUrl>captcha.jpg?captchaCodeId=" + fieldName + "&unique=_PLACEHOLDER_</...@ofbizUrl>";
var unique = Date.now();
captchaUri = captchaUri.replace("_PLACEHOLDER_", unique);
- document.getElementById("captchaImage").src = captchaUri;
- }
- function submitNewCustForm(){
- var nform = document.newuserform;
- nform.captcha.value = document.captchaform.captcha.value;
- nform.submit();
+ document.getElementById(fieldName).src = captchaUri;
}
//-->
</script>
<tr>
<td class="label"> </td>
<td>
- <a href="javascript:reloadCaptcha();">${uiLabelMap.CommonReloadCaptchaCode}</a>
+ <a href="javascript:reloadCaptcha('captchaImage');">${uiLabelMap.CommonReloadCaptchaCode}</a>
</td>
</tr>
<tr>