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 com.methodhead.util.OperationContext;
41: import org.apache.commons.lang.StringUtils;
42:
43: public class UserForm extends AikpForm implements Serializable {
44:
45: public ActionErrors doValidate(ActionMapping mapping,
46: HttpServletRequest request, ActionErrors errors) {
47:
48: if (!errors.isEmpty())
49: return errors;
50:
51: if ("saveNew".equals(get("action"))) {
52:
53: if (StringUtils.isBlank((String) get("password"))) {
54: errors.add("password", new ActionError(
55: "reg.user.missingpassword"));
56: return errors;
57: }
58:
59: if (!get("verifypassword").equals(get("password"))) {
60: errors.add("verifypassword", new ActionError(
61: "reg.user.verifypasswordmismatch"));
62: return errors;
63: }
64:
65: User user = new User();
66: if (user.loadForLogin((String) get("email"))) {
67: errors.add("email", new ActionError(
68: "reg.user.userExists"));
69: return errors;
70: }
71: }
72:
73: else if ("save".equals(get("action"))) {
74:
75: if (!StringUtils.isBlank((String) get("password"))) {
76:
77: if (!get("verifypassword").equals(get("password"))) {
78: errors.add("verifypassword", new ActionError(
79: "reg.user.verifypasswordmismatch"));
80: return errors;
81: }
82: }
83:
84: User user = new User();
85: if (user.loadForLogin((String) get("email"))) {
86: if (user.getInt("id") != Integer
87: .parseInt((String) get("id"))) {
88: errors.add("email", new ActionError(
89: "reg.user.userExists"));
90: return errors;
91: }
92: }
93: }
94:
95: return errors;
96: }
97: }
|