r10015 - in apps/gobi/trunk/code: Page User

[email protected] Sat, 13 Mar 2010 22:27:16 +0100 (CET)
Newsgroups gmane.comp.java.helma.cvs
Message-ID <20100313212716.15B1A3D0E2@mia>
Author: hannes
Date: 2010-03-13 22:27:15 +0100 (Sat, 13 Mar 2010)
New Revision: 10015

Modified:
   apps/gobi/trunk/code/Page/PageActions.js
   apps/gobi/trunk/code/Page/Permissions.js
   apps/gobi/trunk/code/User/create.skin
Log:
Implement simple captcha for user registration page


Details at http://dev.helma.org/trac/helma/changeset/10015

Modified: apps/gobi/trunk/code/Page/PageActions.js
===================================================================
--- apps/gobi/trunk/code/Page/PageActions.js	2010-02-22 15:14:24 UTC (rev 10014)
+++ apps/gobi/trunk/code/Page/PageActions.js	2010-03-13 21:27:15 UTC (rev 10015)
@@ -20,6 +20,7 @@
 
 app.addRepository("modules/core/Object.js");
 app.addRepository("modules/helma/Mail.js");
+app.addRepository("modules/jala/code/Captcha.js");
 
 //////////////////////////// actions////////////////////////////////
 
@@ -725,6 +726,9 @@
         if (name && name.length > 0) {
             if (users.get(name)) {
                 res.message = msg("register_user_exists", name);
+            } else if (!req.data.captcha || !session.data.captcha || 
+                    !session.data.captcha.validate(req.data.captcha)) {
+                res.message = "Sorry, incorrect Captcha. Please try again.";
             } else {
                 it.readEditForm(true);
                 if (!res.data.errors) {
@@ -754,11 +758,18 @@
     if (req.isPost()) {
         it.readEditForm(false);
     }
+    session.data.captcha = new jala.Captcha();
     res.data.body = "<h3>" + msg("register_please") + "</h3>";
     res.data.body += it.renderSkinAsString("create");
     this.renderSkin("page");
 }
 
+function captcha_action() {
+    if (session.data.captcha) {
+        session.data.captcha.renderImage();
+    }
+}
+
 /**
  * 404 action
  */

Modified: apps/gobi/trunk/code/Page/Permissions.js
===================================================================
--- apps/gobi/trunk/code/Page/Permissions.js	2010-02-22 15:14:24 UTC (rev 10014)
+++ apps/gobi/trunk/code/Page/Permissions.js	2010-03-13 21:27:15 UTC (rev 10015)
@@ -62,6 +62,7 @@
     notfound: true, 
     javascript: true, 
     stylesheet: true,
+    captcha: true,
     test: true
 }
 

Modified: apps/gobi/trunk/code/User/create.skin
===================================================================
--- apps/gobi/trunk/code/User/create.skin	2010-02-22 15:14:24 UTC (rev 10014)
+++ apps/gobi/trunk/code/User/create.skin	2010-03-13 21:27:15 UTC (rev 10015)
@@ -12,7 +12,10 @@
 
 <% this.formEditor %>
 
-<br>
+<img src="captcha" alt="captcha"><br>
+Enter Captcha (reload to get a new one)<br>
+<input name="captcha">
+<br><br>
 
 <input type="submit" name="save" value="Save">
 </form>