KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.commons.lang.StringUtils;
41
42 public class ProfileForm
43 extends
44   DynaValidatorForm
45 implements
46   Serializable JavaDoc {
47
48   public ActionErrors validate(
49     ActionMapping mapping,
50     HttpServletRequest JavaDoc request ) {
51
52     //
53
// don't do anything if we're cancelling
54
//
55
if ( !StringUtils.isBlank( ( String JavaDoc )get( "cancel" ) ) )
56       return new ActionErrors();
57
58     ActionErrors errors = super.validate( mapping, request );
59
60     if ( !errors.isEmpty() )
61       return errors;
62
63     //
64
// user exists but isn't current user?
65
//
66
RegPolicy policy = ( RegPolicy )StrutsUtil.getPolicy( mapping );
67     User user = ( User )policy.newRegUser();
68
69     if ( user.loadForLogin( ( String JavaDoc )get( "email" ) ) ) {
70       User cur = ( User )AuthUtil.getUser( request );
71       if ( user.getInt( "id" ) != cur.getInt( "id" ) ) {
72         errors.add(
73           "email", new ActionError( "reg.profile.userExists" ) );
74         return errors;
75       }
76     }
77
78     return errors;
79   }
80 }
81
Popular Tags