KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > reg > PasswordForm


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21
22 package com.methodhead.reg;
23
24 import java.io.Serializable JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26
27 import org.apache.struts.action.ActionMapping;
28 import org.apache.struts.action.ActionErrors;
29 import org.apache.struts.action.ActionError;
30 import org.apache.struts.validator.DynaValidatorForm;
31 import com.methodhead.aikp.AikpForm;
32 import com.methodhead.auth.AuthUtil;
33 import java.util.List JavaDoc;
34 import java.util.ArrayList JavaDoc;
35 import java.util.Iterator JavaDoc;
36 import org.apache.struts.Globals;
37 import org.apache.struts.util.LabelValueBean;
38 import org.apache.struts.util.MessageResources;
39 import com.methodhead.sitecontext.SiteContext;
40 import com.methodhead.util.StrutsUtil;
41 import org.apache.commons.lang.StringUtils;
42
43 public class PasswordForm
44 extends
45   DynaValidatorForm
46 implements
47   Serializable JavaDoc {
48
49   public ActionErrors validate(
50     ActionMapping mapping,
51     HttpServletRequest JavaDoc request ) {
52
53     //
54
// don't do anything if we're cancelling
55
//
56
if ( !StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) )
57       return new ActionErrors();
58
59     ActionErrors errors = super.validate( mapping, request );
60
61     if ( !errors.isEmpty() )
62       return errors;
63
64     User cur = ( User )AuthUtil.getUser( request );
65
66     //
67
// old password incorrect?
68
//
69
if ( !cur.authenticate( ( String JavaDoc )get( "oldpassword" ) ) )
70       errors.add(
71         "oldpassword", new ActionError( "reg.password.incorrectoldpassword" ) );
72
73     //
74
// verify password doesn't match password?
75
//
76
if ( !get( "password" ).equals( get( "verifypassword" ) ) )
77       errors.add(
78         "verifypassword",
79         new ActionError( "reg.password.verifypasswordmismatch" ) );
80
81     return errors;
82   }
83 }
84
Popular Tags