[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/captcha ...

Christian Bauer christian at hibernate.org
Fri Aug 17 09:00:31 EDT 2007


  User: cbauer  
  Date: 07/08/17 09:00:31

  Modified:    examples/wiki/src/main/org/jboss/seam/wiki/core/captcha 
                        WikiCaptcha.java
  Log:
  Major refactoring of core data schema and some new features
  
  Revision  Changes    Path
  1.2       +34 -9     jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/captcha/WikiCaptcha.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: WikiCaptcha.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/captcha/WikiCaptcha.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- WikiCaptcha.java	21 Apr 2007 08:13:50 -0000	1.1
  +++ WikiCaptcha.java	17 Aug 2007 13:00:31 -0000	1.2
  @@ -1,33 +1,50 @@
  +/*
  + * JBoss, Home of Professional Open Source
  + *
  + * Distributable under LGPL license.
  + * See terms of license at gnu.org.
  + */
   package org.jboss.seam.wiki.core.captcha;
   
  +import org.jboss.seam.Component;
  +import org.jboss.seam.ScopeType;
  +import org.jboss.seam.annotations.Create;
   import org.jboss.seam.annotations.Install;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
  -import org.jboss.seam.ScopeType;
  -import org.jboss.seam.Component;
   import org.jboss.seam.contexts.Contexts;
   
   import java.io.Serializable;
  -import java.util.Random;
   import java.security.SecureRandom;
  +import java.util.Random;
   
  +/**
  + * Supertrivial replacement for the broken JCaptcha stuff.
  + *
  + * TODO: Replace with good captcha image generator.
  + *
  + * @author Christian Bauer
  + */
   @Name("org.jboss.seam.captcha.captcha")
   @Scope(ScopeType.PAGE)
   @Install(precedence = Install.DEPLOYMENT)
   public class WikiCaptcha implements Serializable {
   
  -    private String question;
  +    private int one;
  +    private int two;
       private transient String response;
       private transient Random myRamdom = new SecureRandom();
   
       public String getQuestion() {
  -        int one = myRamdom.nextInt(50);
  -        int two = myRamdom.nextInt(50);
  -        question = String.valueOf(one + two);
  -        response = null;
           return one + " + " + two;
       }
   
  +    @Create
  +    public void reset() {
  +        one = myRamdom.nextInt(50);
  +        two = myRamdom.nextInt(50);
  +    }
  +
       @WikiCaptchaResponse
       public String getResponse() {
           return response;
  @@ -38,7 +55,15 @@
       }
   
       public boolean validateResponse(String response) {
  -        return question.equals(response);
  +        if (new Integer(one + two).equals(new Integer(response))) {
  +            // TODO: Fuck that, doesn't clean out the old value.... no idea why
  +            this.response = null;
  +            reset();
  +            return true;
  +        } else {
  +            this.response = null;
  +            return false;
  +        }
       }
   
       public static WikiCaptcha instance() {
  
  
  



More information about the jboss-cvs-commits mailing list