01: /*
02: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
03: *
04: * This file is part of TransferCM.
05: *
06: * TransferCM is free software; you can redistribute it and/or modify it under the
07: * terms of the GNU General Public License as published by the Free Software
08: * Foundation; either version 2 of the License, or (at your option) any later
09: * 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;
24: import javax.servlet.http.HttpServletRequest;
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;
33: import java.util.ArrayList;
34: import java.util.Iterator;
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 extends DynaValidatorForm implements
43: Serializable {
44:
45: public ActionErrors validate(ActionMapping mapping,
46: HttpServletRequest request) {
47:
48: //
49: // don't do anything if we're cancelling
50: //
51: if (!StringUtils.isBlank((String) get("cancel")))
52: return new ActionErrors();
53:
54: ActionErrors errors = super .validate(mapping, request);
55:
56: if (!errors.isEmpty())
57: return errors;
58:
59: //
60: // user exists but isn't current user?
61: //
62: RegPolicy policy = (RegPolicy) StrutsUtil.getPolicy(mapping);
63: User user = (User) policy.newRegUser();
64:
65: if (user.loadForLogin((String) get("email"))) {
66: User cur = (User) AuthUtil.getUser(request);
67: if (user.getInt("id") != cur.getInt("id")) {
68: errors.add("email", new ActionError(
69: "reg.profile.userExists"));
70: return errors;
71: }
72: }
73:
74: return errors;
75: }
76: }
|