001: /*
002: * Created on Feb 3, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.form;
008:
009: import org.apache.struts.Globals;
010: import org.apache.struts.action.ActionError;
011: import org.apache.struts.action.ActionErrors;
012: import org.apache.struts.action.ActionForm;
013: import org.apache.struts.action.ActionMapping;
014: import org.apache.struts.util.MessageResources;
015: import java.util.Locale;
016: import javax.servlet.http.HttpServletRequest;
017:
018: /**
019: * LoginForm purpose.
020: * <p>
021: * Stores the username/password information for the login page, to be used by the LoginAction
022: * </p>
023: *
024: * @author rgould, Refractions Research, Inc.
025: * @author $Author: dmzwiers $ (last modification)
026: * @version $Id: LoginForm.java 6177 2007-02-19 10:11:27Z aaime $
027: */
028: public class LoginForm extends ActionForm {
029: /**
030: * Comment for <code>serialVersionUID</code>
031: */
032: private static final long serialVersionUID = 3258410616858358324L;
033: private String username;
034: private String password;
035: private String confirm;
036:
037: /**
038: *
039: * sets username and password to empty strings
040: *
041: * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
042: *
043: * @param arg0
044: * @param request
045: */
046: public void reset(ActionMapping arg0, HttpServletRequest request) {
047: super .reset(arg0, request);
048:
049: username = "";
050: password = "";
051: confirm = "";
052: }
053:
054: /**
055: *
056: * Verifies that username is not null or empty.
057: * Could potentially do the same for password later.
058: *
059: * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
060: *
061: * @param mapping
062: * @param request
063: * @return
064: */
065: public ActionErrors validate(ActionMapping mapping,
066: HttpServletRequest request) {
067: ActionErrors errors = new ActionErrors();
068:
069: Locale locale = (Locale) request.getLocale();
070:
071: //MessageResources messages = servlet.getResources();
072: //TODO: not sure about this, changed for struts 1.2.8 upgrade
073: MessageResources messages = (MessageResources) request
074: .getAttribute(Globals.MESSAGES_KEY);
075:
076: String usernameLabel = messages.getMessage(locale,
077: "label.username");
078: String passwordLabel = messages.getMessage(locale,
079: "label.password");
080:
081: if ((username == null) || username.equals("")) {
082: errors.add("username", new ActionError("errors.required",
083: usernameLabel));
084: }
085:
086: if ((password == null) || password.equals("")) {
087: errors.add("password", new ActionError("errors.required",
088: passwordLabel));
089: }
090:
091: //failed experiment, as it looks like Login and LoginEdit use the same
092: //form, which means that confirm will always be null on the normal.
093: //I think the best course of action would be to have a LoginEditForm,
094: //which extends this class, just adding the confirm stuff, and does the
095: //validate with the confirm. We don't want the normal login using
096: //the validate, which is why this experiment failed. Shouldn't be
097: //too hard, it's just getting late and I've spent too much time on this
098: //already.
099:
100: //if (confirm == null || !confirm.equals(password)) {
101: // errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.password.mismatch"));
102: //}
103: return errors;
104: }
105:
106: /**
107: * Access password property.
108: *
109: * @return Returns the password.
110: */
111: public String getPassword() {
112: return password;
113: }
114:
115: /**
116: * Set password to password.
117: *
118: * @param password The password to set.
119: */
120: public void setPassword(String password) {
121: this .password = password;
122: }
123:
124: /**
125: * Access username property.
126: *
127: * @return Returns the username.
128: */
129: public String getUsername() {
130: return username;
131: }
132:
133: /**
134: * Set username to username.
135: *
136: * @param username The username to set.
137: */
138: public void setUsername(String username) {
139: this .username = username;
140: }
141:
142: public String getConfirm() {
143: return confirm;
144: }
145:
146: public void setConfirm(String confirm) {
147: this.confirm = confirm;
148: }
149: }
|