001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: Register.java,v 1.1 2006-09-11 12:30:36 sinisa Exp $
022: */
023:
024: package barracudaDiscRack.presentation.personMgmt;
025:
026: import barracudaDiscRack.business.person.*;
027: import barracudaDiscRack.presentation.BasePO;
028: import com.lutris.appserver.server.httpPresentation.*;
029: import com.lutris.appserver.server.session.*;
030: import com.lutris.util.*;
031: import org.enhydra.xml.xmlc.*;
032: import org.enhydra.xml.xmlc.html.*;
033: import org.w3c.dom.*;
034: import org.w3c.dom.html.*;
035: import org.enhydra.xml.xmlc.XMLObject;
036: import barracudaDiscRack.presentation.DiscRackPresentationException;
037: import barracudaDiscRack.business.DiscRackBusinessException;
038:
039: /**
040: * Register.java handles the user registration functionality
041: * of the DiscRack app.
042: *
043: * @author
044: * @version
045: */
046: public class Register extends BasePO {
047:
048: /**
049: * Constants
050: */
051: private static String LOGINNAME = "login";
052: private static String PASSWORD = "password";
053: private static String REPASSWORD = "repassword";
054: private static String FIRSTNAME = "firstname";
055: private static String LASTNAME = "lastname";
056:
057: /**
058: * Superclass method override
059: */
060: public boolean loggedInUserRequired() {
061: return false;
062: }
063:
064: /**
065: * Default event. Just show the page.
066: *
067: * @return html document
068: * @exception HttpPresentationException
069: */
070: public XMLObject handleDefault() throws HttpPresentationException {
071: return showPage(null);
072: }
073:
074: /**
075: * process login data, save fields to PersonManager if correct,
076: * otherwise output error messages
077: *
078: * @return html document
079: * @exception HttpPresentationException
080: */
081: public XMLObject handleRegister() throws HttpPresentationException {
082:
083: String login = this .getComms().request.getParameter(LOGINNAME);
084: String password = this .getComms().request
085: .getParameter(PASSWORD);
086: String firstname = this .getComms().request
087: .getParameter(FIRSTNAME);
088: ;
089: String lastname = this .getComms().request
090: .getParameter(LASTNAME);
091: String repassword = this .getComms().request
092: .getParameter(REPASSWORD);
093:
094: // if login or password field is empty, generate error and redirect to this PO
095: if (login.length() == 0 || password.length() == 0
096: || firstname.length() == 0 || lastname.length() == 0) {
097: return showPage("Missing information. Please make sure all fields are filled out exactly");
098: }
099:
100: //Check that password was duplicated correctly
101: if (!repassword.equals(password)) {
102: return showPage("Please make sure your password and password confirmation match exactly");
103: }
104:
105: try {
106: // Now check that the login name is not taken.
107: if (null == PersonFactory.findPerson(login)) {
108: Person user = new Person();
109: user.setLogin(login);
110: user.setPassword(password);
111: user.setFirstname(firstname);
112: user.setLastname(lastname);
113: //Add the user to the database.
114: user.save();
115: this .getSessionData().setUserMessage(
116: "You are registered, " + user.getFirstname()
117: + ", please log in");
118: throw new ClientPageRedirectException(
119: getComms().request.getApplicationPath()
120: + LOGIN_PAGE);
121: } else {
122: // Login name already taken
123: // Redirect to this same PO with informative error message
124: return showPage("The login name " + login
125: + " is already taken. Please try another.");
126: }
127: } catch (DiscRackBusinessException ex) {
128: throw new DiscRackPresentationException(
129: "Exception logging in user: ", ex);
130: }
131: }
132:
133: /**
134: * display page
135: *
136: * @param errorMsg, the error messages
137: * @return html document
138: * @exception HttpPresentationException
139: */
140: public XMLObject showPage(String errorMsg)
141: throws HttpPresentationException {
142:
143: RegisterHTML page = (RegisterHTML) myComms.xmlcFactory
144: .create(RegisterHTML.class);
145:
146: if (null == errorMsg) {
147: page.getElementErrorText().getParentNode().removeChild(
148: page.getElementErrorText());
149: } else {
150: page.setTextErrorText(errorMsg);
151: }
152:
153: if (null != this.getComms().request.getParameter(LOGINNAME)) {
154: page.getElementLogin().setValue(
155: this.getComms().request.getParameter(LOGINNAME));
156: }
157: if (null != this.getComms().request.getParameter(FIRSTNAME)) {
158: page.getElementFirstname().setValue(
159: this.getComms().request.getParameter(FIRSTNAME));
160: }
161: if (null != this.getComms().request.getParameter(LASTNAME)) {
162: page.getElementLastname().setValue(
163: this.getComms().request.getParameter(LASTNAME));
164: }
165:
166: return page;
167: }
168: }
|