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:47:00 sinisa Exp $
022: */
023:
024: package transactionsDiscRack.presentation.personMgmt;
025:
026: import transactionsDiscRack.presentation.BasePO;
027: import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException;
028: import transactionsDiscRack.spec.*;
029:
030: import com.lutris.appserver.server.httpPresentation.*;
031: import org.enhydra.xml.xmlc.XMLObject;
032:
033: import org.enhydra.dods.exceptions.AssertionDataObjectException;
034:
035: /**
036: * Register.java handles the user registration functionality
037: * of the DiscRack app.
038: *
039: */
040: public class Register extends BasePO {
041:
042: /**
043: * Constants
044: */
045: private static String LOGINNAME = "login";
046:
047: private static String PASSWORD = "password";
048:
049: private static String REPASSWORD = "repassword";
050:
051: private static String FIRSTNAME = "firstname";
052:
053: private static String LASTNAME = "lastname";
054:
055: /**
056: * Superclass method override
057: */
058: public boolean loggedInUserRequired() {
059: return false;
060: }
061:
062: /**
063: * Default event. Just show the page.
064: *
065: * @return html document
066: * @exception HttpPresentationException
067: */
068: public XMLObject handleDefault() throws HttpPresentationException {
069: return showPage(null);
070: }
071:
072: /**
073: * process login data, save fields to PersonManager if correct,
074: * otherwise output error messages
075: *
076: * @return html document
077: * @exception HttpPresentationException
078: */
079: public XMLObject handleRegister() throws HttpPresentationException {
080:
081: String login = this .getComms().request.getParameter(LOGINNAME);
082: String password = this .getComms().request
083: .getParameter(PASSWORD);
084: String firstname = this .getComms().request
085: .getParameter(FIRSTNAME);
086: String lastname = this .getComms().request
087: .getParameter(LASTNAME);
088: String repassword = this .getComms().request
089: .getParameter(REPASSWORD);
090:
091: // if login or password field is empty, generate error and redirect to this PO
092: if (login.length() == 0 || password.length() == 0
093: || firstname.length() == 0 || lastname.length() == 0) {
094: return showPage("Missing information. Please make sure all fields are filled out exactly");
095: }
096:
097: //Check that password was duplicated correctly
098: if (!repassword.equals(password)) {
099: return showPage("Please make sure your password and password confirmation match exactly");
100: }
101:
102: /*
103: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run transactionsDiscRack_pres )
104: * We need to allow discRack_pres to be functional , response
105: * will be default HTML page with message
106: */
107: try {
108: Person user = ((PersonGenerator) PersonGeneratorFactory
109: .getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl"))
110: .findPerson(login, this .transaction);
111:
112: // Now check that the login name is not taken.
113: if (null == user) {
114:
115: user = PersonFactory
116: .getPerson("transactionsDiscRack.business.person.PersonImpl");
117:
118: user.setLogin(login);
119: user.setPassword(password);
120: user.setFirstname(firstname);
121: user.setLastname(lastname);
122:
123: //Add the user to the database.
124: user.save(this .transaction);
125:
126: this .getSessionData().setUserMessage(
127: "You are registered, " + user.getFirstname()
128: + ", please log in");
129: throw new ClientPageRedirectException(
130: getComms().request.getApplicationPath()
131: + LOGIN_PAGE);
132: } else {
133: // Login name already taken
134: // Redirect to this same PO with informative error message
135: return showPage("The login name " + login
136: + " is already taken. Please try another.");
137: }
138: } catch (AssertionDataObjectException ex) {
139: return showPage("Table person is read-only: can't register another person.");
140: } catch (TransactionsDiscRackException ex) {
141: throw new TransactionsDiscRackPresentationException(
142: "Exception logging in user: ", ex);
143: } catch (Exception ex) {
144: return showPage("You canot register while you in presentation mode!");
145: }
146: }
147:
148: /**
149: * display page
150: *
151: * @param errorMsg the error messages
152: * @return html document
153: * @exception HttpPresentationException
154: */
155: public XMLObject showPage(String errorMsg)
156: throws HttpPresentationException {
157:
158: RegisterHTML page = (RegisterHTML) myComms.xmlcFactory
159: .create(RegisterHTML.class);
160:
161: if (null == errorMsg) {
162: page.getElementErrorText().getParentNode().removeChild(
163: page.getElementErrorText());
164: } else {
165: page.setTextErrorText(errorMsg);
166: }
167:
168: if (null != this.getComms().request.getParameter(LOGINNAME)) {
169: page.getElementLogin().setValue(
170: this.getComms().request.getParameter(LOGINNAME));
171: }
172: if (null != this.getComms().request.getParameter(FIRSTNAME)) {
173: page.getElementFirstname().setValue(
174: this.getComms().request.getParameter(FIRSTNAME));
175: }
176: if (null != this.getComms().request.getParameter(LASTNAME)) {
177: page.getElementLastname().setValue(
178: this.getComms().request.getParameter(LASTNAME));
179: }
180:
181: return page;
182: }
183: }
|