View Javadoc

1   package org.sourceforge.vlibrary.security.forms;
2   
3   import org.apache.struts.action.ActionForm;
4   import javax.servlet.http.HttpServletRequest;
5   import org.apache.struts.action.ActionMessage;
6   import org.apache.struts.action.ActionErrors;
7   import org.apache.struts.action.ActionMapping;
8   
9   /**
10   * Password reset form
11   * @version $Revision$ $Date$
12   */
13  
14  public class PasswordResetForm extends ActionForm {
15      private static final long serialVersionUID = 0;
16      
17      private String pwd = null;
18      private String confirmPwd = null;
19      
20      public String getConfirmPwd() {
21          return confirmPwd;
22      }
23      
24      public void setConfirmPwd(String confirmPwd) {
25          this.confirmPwd = confirmPwd;
26      }
27      
28      public String getPwd() {
29          return pwd;
30      }
31      
32      public void setPwd(String pwd) {
33          this.pwd = pwd;
34      }
35      
36      public void reset(ActionMapping mapping, HttpServletRequest request) {
37          this.pwd = null;
38          this.confirmPwd=null;
39      }
40      
41      /**
42       * Validate the properties that have been set from this HTTP request,
43       * and return an <code>ActionErrors</code> object that encapsulates any
44       * validation errors that have been found.  If no errors are found, return
45       * <code>null</code> or an <code>ActionErrors</code> object with no
46       * recorded error messages.
47       *
48       * @param mapping The mapping used to select this instance
49       * @param request The servlet request we are processing
50       */
51      public ActionErrors validate(ActionMapping mapping,
52       HttpServletRequest request) {
53          ActionErrors errors = new ActionErrors();
54          
55          if ((pwd == null) || (pwd.length() < 1))
56              errors.add("pwd",
57               new ActionMessage("error.reader.password.required"));
58          
59          if ((confirmPwd == null) || (confirmPwd.length() < 1))
60              errors.add("confirmPwd",
61               new ActionMessage
62               ("error.reader.password.confirmation.required"));
63          
64          // Check password/confirmation match
65          if (!(pwd.equals(confirmPwd)))
66              errors.add("password",
67               new ActionMessage("error.reader.confirmPwdFailed"));
68          
69          return errors;
70      }
71  }