KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > pim > presentation > enhydrapim > Register


1 /*
2  * Created on May 6, 2005
3  *
4  */

5 package org.enhydra.pim.presentation.enhydrapim;
6
7 import org.enhydra.pim.business.UserManagerI;
8 import org.enhydra.pim.business.api.OwnerI;
9 import org.enhydra.pim.presentation.BasePO;
10 import org.enhydra.pim.spec.UserManagerFactory;
11 import org.enhydra.xml.xmlc.XMLObject;
12
13 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
14 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
15
16 /**
17  * @author P.Djojic May 6, 2005 1:20:59 AM
18  *
19  * TODO Register
20  */

21 public class Register extends BasePO {
22
23     private static final String JavaDoc PASSWORD2 = "password2";
24
25     private static final String JavaDoc PASSWORD1 = "password1";
26
27     private static final String JavaDoc USERNAME = "userName";
28
29     /*
30      * (non-Javadoc)
31      *
32      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#handleDefault()
33      */

34     public XMLObject handleDefault() throws HttpPresentationException {
35         return showPage();
36     }
37
38     /*
39      * (non-Javadoc)
40      *
41      * @see org.enhydra.pim.presentation.enhydrapim.BasePO#loggedInUserRequired()
42      */

43     protected boolean loggedInUserRequired() {
44         // TODO Auto-generated method stub
45
return false;
46     }
47
48     /**
49      * process login data, save fields to UserManager if correct, otherwise
50      * output error messages
51      *
52      * @return html document
53      * @exception HttpPresentationException
54      */

55     public XMLObject handleRegister() throws HttpPresentationException {
56
57         String JavaDoc userName = this.getComms().request.getParameter(USERNAME);
58         String JavaDoc password1 = this.getComms().request.getParameter(PASSWORD1);
59         String JavaDoc password2 = this.getComms().request.getParameter(PASSWORD2);
60
61         // if login or password field is empty, generate error and redirect to
62
// this PO
63
if (userName.length() == 0 || password1.length() == 0 || password1.length() == 0) {
64             return showErrorPage("Missing information. Please make sure all fields are filled out exactly");
65         }
66
67         //Check that password was duplicated correctly
68
if (!password1.equals(password2)) {
69             return showErrorPage("Please make sure your password and password confirmation match exactly");
70         }
71
72         /*
73          * Catch Null pointer exception ( we canot make a instances of classes
74          * from business layer when we run discRack_pres ) We need to allow
75          * discRack_pres to be functional , response will be default HTML page
76          * with message
77          */

78
79         try {
80             UserManagerI uMan = UserManagerFactory.getUserManager();
81             OwnerI user = uMan.checkOwner(userName, password1);
82             // Now check that the login name is not taken.
83
if (user == null) {
84                 uMan.registerOwner(userName, password1);
85                 this.getSessionData().setUserMessage("You are registered, " + userName + ", please log in");
86                 throw new ClientPageRedirectException(LOGIN_PAGE);
87                 // getComms().response.getHttpServletResponse().sendRedirect(getComms().request.getApplicationPath()
88
// + LOGIN_PAGE);
89
// return showErrorPage("Error during login operation");
90
} else {
91                 return showErrorPage("The login name " + userName + " is already taken. Please try another.");
92             }
93         } catch (Exception JavaDoc ex) {
94             return showErrorPage("Exception during login operation");
95         }
96
97     }
98
99     /**
100      * display page
101      *
102      * @return html document
103      * @exception HttpPresentationException
104      */

105     public XMLObject showPage() throws HttpPresentationException {
106         RegisterHTML page = (RegisterHTML) myComms.xmlcFactory.create(RegisterHTML.class);
107         return page;
108     }
109
110 }
Popular Tags