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:59:02 UTC

svn commit: r1338712 - in /ofbiz/branches/release11.04: ./ framework/common/src/org/ofbiz/common/ specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/ specialpurpose/ecommerce/webapp/ecommerce/customer/ specialpurpose/myportal/script/org/ofbiz...

Author: jacopoc
Date: Tue May 15 13:59:01 2012
New Revision: 1338712

URL: http://svn.apache.org/viewvc?rev=1338712&view=rev
Log:
Applied fix from trunk for revision: 1338700 
===

Completed refactoring/cleanup of captcha implementation that now supports screens with more than one captcha in them.

Removed:
    ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/Captcha.java
    ofbiz/branches/release11.04/specialpurpose/myportal/widget/MyPortalForms.xml
Modified:
    ofbiz/branches/release11.04/   (props changed)
    ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/CommonEvents.java
    ofbiz/branches/release11.04/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
    ofbiz/branches/release11.04/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl
    ofbiz/branches/release11.04/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml
    ofbiz/branches/release11.04/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml
    ofbiz/branches/release11.04/specialpurpose/myportal/widget/CommonScreens.xml
    ofbiz/branches/release11.04/specialpurpose/myportal/widget/RegisterPerson.ftl

Propchange: ofbiz/branches/release11.04/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1338361-1338366,1338372-1338394,1338700

Modified: ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/CommonEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/CommonEvents.java?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/CommonEvents.java (original)
+++ ofbiz/branches/release11.04/framework/common/src/org/ofbiz/common/CommonEvents.java Tue May 15 13:59:01 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;
@@ -381,11 +382,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]);
@@ -465,7 +467,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/branches/release11.04/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml (original)
+++ ofbiz/branches/release11.04/specialpurpose/ecommerce/script/org/ofbiz/ecommerce/customer/CustomerEvents.xml Tue May 15 13:59:01 2012
@@ -1279,7 +1279,7 @@ under the License.
             </else>
         </if-empty>
         <call-object-method obj-field="parameters.captcha" method-name="toLowerCase" ret-field="submittedCaptcha"/>
-        <set field="actualCaptcha" value="${groovy: request.getSession().getAttribute('_CAPTCHA_CODE_')?.toLowerCase()}"/>
+        <set field="actualCaptcha" value="${groovy: request.getSession().getAttribute('_CAPTCHA_CODE_')?.get('captchaImage')?.toLowerCase()}"/>
         <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/branches/release11.04/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl (original)
+++ ofbiz/branches/release11.04/specialpurpose/ecommerce/webapp/ecommerce/customer/AnonContactus.ftl Tue May 15 13:59:01 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 + "&amp;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/branches/release11.04/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml (original)
+++ ofbiz/branches/release11.04/specialpurpose/myportal/script/org/ofbiz/myportal/Events.xml Tue May 15 13:59:01 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"/>
-        <set field="actualCaptcha" value="${groovy: request.getSession().getAttribute('_CAPTCHA_CODE_')?.toLowerCase()}"/>
+        <set field="actualCaptcha" value="${groovy: request.getSession().getAttribute('_CAPTCHA_CODE_')?.get('captchaImage')?.toLowerCase()}"/>
         <if-compare field="parameters.PASSWORD" value="${parameters.CONFIRM_PASSWORD}" operator="equals">
             <if-compare-field operator="equals" field="submittedCaptcha" to-field="actualCaptcha">
 

Modified: ofbiz/branches/release11.04/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml (original)
+++ ofbiz/branches/release11.04/specialpurpose/myportal/webapp/myportal/WEB-INF/controller.xml Tue May 15 13:59:01 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/branches/release11.04/specialpurpose/myportal/widget/CommonScreens.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/myportal/widget/CommonScreens.xml?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/myportal/widget/CommonScreens.xml (original)
+++ ofbiz/branches/release11.04/specialpurpose/myportal/widget/CommonScreens.xml Tue May 15 13:59:01 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/branches/release11.04/specialpurpose/myportal/widget/RegisterPerson.ftl
URL: http://svn.apache.org/viewvc/ofbiz/branches/release11.04/specialpurpose/myportal/widget/RegisterPerson.ftl?rev=1338712&r1=1338711&r2=1338712&view=diff
==============================================================================
--- ofbiz/branches/release11.04/specialpurpose/myportal/widget/RegisterPerson.ftl (original)
+++ ofbiz/branches/release11.04/specialpurpose/myportal/widget/RegisterPerson.ftl Tue May 15 13:59:01 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 + "&amp;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>