KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.methodhead.reg;
22
23 import java.io.Serializable JavaDoc;
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionErrors;
28 import org.apache.struts.action.ActionError;
29 import org.apache.struts.validator.DynaValidatorForm;
30 import com.methodhead.aikp.AikpForm;
31 import com.methodhead.auth.AuthUtil;
32 import java.util.List JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import org.apache.struts.Globals;
36 import org.apache.struts.util.LabelValueBean;
37 import org.apache.struts.util.MessageResources;
38 import com.methodhead.sitecontext.SiteContext;
39 import com.methodhead.util.StrutsUtil;
40 import com.methodhead.util.OperationContext;
41 import org.apache.commons.lang.StringUtils;
42
43 public class UserForm
44 extends
45   AikpForm
46 implements
47   Serializable JavaDoc {
48
49   public ActionErrors doValidate(
50     ActionMapping mapping,
51     HttpServletRequest JavaDoc request,
52     ActionErrors errors ) {
53
54     if ( !errors.isEmpty() )
55       return errors;
56
57     if ( "saveNew".equals( get( "action" ) ) ) {
58
59       if ( StringUtils.isBlank( ( String JavaDoc )get( "password" ) ) ) {
60         errors.add( "password", new ActionError( "reg.user.missingpassword" ) );
61         return errors;
62       }
63
64       if ( !get( "verifypassword" ).equals( get( "password" ) ) ) {
65         errors.add(
66           "verifypassword", new ActionError( "reg.user.verifypasswordmismatch" ) );
67         return errors;
68       }
69
70       User user = new User();
71       if ( user.loadForLogin( ( String JavaDoc )get( "email" ) ) ) {
72         errors.add(
73           "email", new ActionError( "reg.user.userExists" ) );
74         return errors;
75       }
76     }
77
78     else if ( "save".equals( get( "action" ) ) ) {
79
80       if ( !StringUtils.isBlank( ( String JavaDoc )get( "password" ) ) ) {
81
82         if ( !get( "verifypassword" ).equals( get( "password" ) ) ) {
83           errors.add(
84             "verifypassword", new ActionError( "reg.user.verifypasswordmismatch" ) );
85           return errors;
86         }
87       }
88
89       User user = new User();
90       if ( user.loadForLogin( ( String JavaDoc )get( "email" ) ) ) {
91         if ( user.getInt( "id" ) != Integer.parseInt( ( String JavaDoc )get( "id" ) ) ) {
92           errors.add(
93             "email", new ActionError( "reg.user.userExists" ) );
94           return errors;
95         }
96       }
97     }
98
99     return errors;
100   }
101 }
102
Popular Tags