KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > personMgmt > Register


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: Register.java,v 1.1 2004/08/16 09:39:21 slobodan Exp $
22  */

23
24 package discRack.presentation.personMgmt;
25
26
27 import discRack.presentation.BasePO;
28 import discRack.presentation.DiscRackPresentationException;
29 import discRack.spec.*;
30
31 import com.lutris.appserver.server.httpPresentation.*;
32 import com.lutris.appserver.server.session.*;
33 import com.lutris.util.*;
34 //import com.lutris.xml.xmlc.*;
35
//import com.lutris.xml.xmlc.html.*;
36
import org.w3c.dom.*;
37 import org.w3c.dom.html.*;
38 import org.enhydra.xml.xmlc.XMLObject;
39
40
41
42
43
44
45 import org.enhydra.dods.exceptions.AssertionDataObjectException;
46
47 /**
48  * Register.java handles the user registration functionality
49  * of the DiscRack app.
50  *
51  */

52 public class Register extends BasePO {
53
54     /**
55      * Constants
56      */

57     private static String JavaDoc LOGINNAME = "login";
58     private static String JavaDoc PASSWORD = "password";
59     private static String JavaDoc REPASSWORD = "repassword";
60     private static String JavaDoc FIRSTNAME = "firstname";
61     private static String JavaDoc LASTNAME = "lastname";
62
63     /**
64      * Superclass method override
65      */

66     public boolean loggedInUserRequired() {
67         return false;
68     }
69
70     /**
71      * Default event. Just show the page.
72      *
73      * @return html document
74      * @exception HttpPresentationException
75      */

76     public XMLObject handleDefault()
77         throws HttpPresentationException {
78         return showPage(null);
79     }
80
81     /**
82      * process login data, save fields to PersonManager if correct,
83      * otherwise output error messages
84      *
85      * @return html document
86      * @exception HttpPresentationException
87      */

88     public XMLObject handleRegister()
89         throws HttpPresentationException {
90
91         String JavaDoc login = this.getComms().request.getParameter(LOGINNAME);
92         String JavaDoc password = this.getComms().request.getParameter(PASSWORD);
93         String JavaDoc firstname = this.getComms().request.getParameter(FIRSTNAME);;
94         String JavaDoc lastname = this.getComms().request.getParameter(LASTNAME);
95         String JavaDoc repassword = this.getComms().request.getParameter(REPASSWORD);
96
97         // if login or password field is empty, generate error and redirect to this PO
98
if (login.length() == 0 || password.length() ==0 ||
99             firstname.length() == 0 || lastname.length() == 0) {
100             return showPage("Missing information. Please make sure all fields are filled out exactly");
101         }
102
103         //Check that password was duplicated correctly
104
if(!repassword.equals(password)) {
105             return showPage("Please make sure your password and password confirmation match exactly");
106         }
107         
108         
109 /*
110  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run discRack_pres )
111  * We need to allow discRack_pres to be functional , response
112  * will be default HTML page with message
113  */

114  try {
115             
116         Person user=((PersonGenerator)PersonGeneratorFactory.getPersonGenerator("discRack.business.person.PersonGeneratorImpl")).findPerson(login);
117             
118             // Now check that the login name is not taken.
119
if(null == user)
120              {
121             
122              user= PersonFactory.getPerson("discRack.business.person.PersonImpl");
123                
124             user.setLogin(login);
125             user.setPassword(password);
126             user.setFirstname(firstname);
127             user.setLastname(lastname);
128           //Add the user to the database.
129
user.save();
130           
131               
132                 this.getSessionData().setUserMessage("You are registered, " +
133                                                      user.getFirstname() + ", please log in");
134                 throw new ClientPageRedirectException(getComms().request.getApplicationPath()+LOGIN_PAGE);
135             } else {
136                 // Login name already taken
137
// Redirect to this same PO with informative error message
138
return showPage("The login name " + login + " is already taken. Please try another.");
139             }
140          }catch(NullPointerException JavaDoc ex){
141             return showPage("You canot register while you in discRack_pres ");
142       
143         }
144         catch (AssertionDataObjectException ex) {
145             return showPage("Table person is read-only: can't register another person.");
146         }
147         catch(DiscRackException ex) {
148             throw new DiscRackPresentationException("Exception logging in user: ", ex);
149         }
150     }
151
152     /**
153      * display page
154      *
155      * @param errorMsg the error messages
156      * @return html document
157      * @exception HttpPresentationException
158      */

159     public XMLObject showPage(String JavaDoc errorMsg)
160         throws HttpPresentationException {
161
162     RegisterHTML page = (RegisterHTML)myComms.xmlcFactory.create(RegisterHTML.class);
163
164         if(null == errorMsg) {
165             page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
166         } else {
167             page.setTextErrorText(errorMsg);
168         }
169
170         if(null != this.getComms().request.getParameter(LOGINNAME)) {
171             page.getElementLogin().setValue(this.getComms().request.getParameter(LOGINNAME));
172         }
173         if(null != this.getComms().request.getParameter(FIRSTNAME)) {
174             page.getElementFirstname().setValue(this.getComms().request.getParameter(FIRSTNAME));
175         }
176         if(null != this.getComms().request.getParameter(LASTNAME)) {
177             page.getElementLastname().setValue(this.getComms().request.getParameter(LASTNAME));
178         }
179
180         return page;
181     }
182 }
183
Popular Tags