Author: michiel
Date: 2010-02-09 15:06:13 +0100 (Tue, 09 Feb 2010)
New Revision: 40934

Modified:
   
mmbase/branches/MMBase-1_9/applications/resources/src/main/java/org/mmbase/datatypes/CaptchaDataType.java
Log:
make sure the key in session is cleared an reused at the right moments

Modified: 
mmbase/branches/MMBase-1_9/applications/resources/src/main/java/org/mmbase/datatypes/CaptchaDataType.java
===================================================================
--- 
mmbase/branches/MMBase-1_9/applications/resources/src/main/java/org/mmbase/datatypes/CaptchaDataType.java
   2010-02-09 14:05:06 UTC (rev 40933)
+++ 
mmbase/branches/MMBase-1_9/applications/resources/src/main/java/org/mmbase/datatypes/CaptchaDataType.java
   2010-02-09 14:06:13 UTC (rev 40934)
@@ -32,6 +32,8 @@
 
     public static final String KEY = CaptchaDataType.class.getName() + ".KEY";
 
+    public static final String CLEAR = CaptchaDataType.class.getName() + 
".CLEAR";
+
     public static final String BASE = "temporary_images";
 
     protected CaptchaRestriction  captchaRestriction =  new 
CaptchaRestriction();
@@ -174,6 +176,9 @@
                     return false;
                 }
                 LOG.debug("Found " + KEY + " is " + value + " (user provided  
'" + v + "')");
+                if (cloud.getProperty(Node.CLOUD_COMMITNODE_KEY) == 
Integer.valueOf(node.getNumber())) {
+                    session.removeAttribute(KEY);
+                }
                 return mustbe.equalsIgnoreCase(Casting.toString(v));
             }
         }
@@ -204,20 +209,37 @@
         }
 
         @Override
+        protected void setValue(Request request, Node node, String fieldName, 
Object value) {
+            super.setValue(request, node, fieldName, value);
+            if (request.isPost()) {
+                HttpServletRequest req = (HttpServletRequest) 
request.getCloud().getProperty(Cloud.PROP_REQUEST);
+                HttpSession session = req.getSession(true);
+                session.removeAttribute(CaptchaDataType.KEY);
+                LOG.debug("Set value now cleaning from session");
+            }
+        }
+
+        @Override
         public String input(Request request, Node node, Field field, boolean 
search)  {
             if (search) {
                 return super.input(request, node, field, search);
             } else {
                 HttpServletRequest req = (HttpServletRequest) 
request.getCloud().getProperty(Cloud.PROP_REQUEST);
                 HttpSession session = req.getSession(true);
-                CaptchaImage image = new 
CaptchaDataType.CaptchaImage(createString(length));
+                String t = (String) session.getAttribute(CaptchaDataType.KEY);
+                if (t == null ||  request.getCloud().getProperty(CLEAR) != 
null) {
+                    t = createString(length);
+                    session.setAttribute(CaptchaDataType.KEY, t);
+                    LOG.debug("Created key now setting in session");
+
+                }
+                CaptchaImage image = new CaptchaDataType.CaptchaImage(t);
                 image.swirl = swirl;
                 image.background = background;
                 image.font = font;
                 StringBuilder show =  new StringBuilder();
                 try {
                     CaptchaDataType.createCaptchaImage(null, image);
-                    session.setAttribute(CaptchaDataType.KEY, image.text);
                     show.append("<img src='");
                     show.append(req.getContextPath());
                     show.append(image.getPath());

_______________________________________________
Cvs mailing list
Cvs@lists.mmbase.org
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to