KickJava   Java API By Example, From Geeks To Geeks.

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


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

5 package org.enhydra.pim.presentation.enhydrapim;
6
7 import org.enhydra.pim.business.api.OwnerI;
8 import org.enhydra.pim.presentation.BasePO;
9 import org.enhydra.pim.presentation.EnhydraPimPresentationException;
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:30:24 AM
18  *
19  * TODO Login
20  */

21 public class Login extends BasePO {
22
23     private static final String JavaDoc LOGIN_USERNAME = "username";
24
25     private static final String JavaDoc LOGIN_PASSWORD = "password";
26
27     /**
28      * Superclass method override
29      */

30     public boolean loggedInUserRequired() {
31         return false;
32     }
33
34     /**
35      * Default event. Just show the page.
36      */

37     public XMLObject handleDefault() throws HttpPresentationException {
38         return showIndexPage();
39     }
40
41     /**
42      * Process login data
43      *
44      * @return wml document
45      * @exception HttpPresentationException
46      */

47     public XMLObject handleLogin() throws HttpPresentationException {
48         String JavaDoc username = this.getComms().request.getParameter(LOGIN_USERNAME);
49         String JavaDoc password = this.getComms().request.getParameter(LOGIN_PASSWORD);
50
51         OwnerI user = null;
52         try {
53
54             user = UserManagerFactory.getUserManager().checkOwner(username, password);
55
56             if (null == user || !user.getPassword().equals(password)) {
57                 return showErrorPage("Invalid username or password");
58                 // Show error message that user not found (bad
59
// username/password)
60
} else {
61                 this.setUser(user);
62                 throw new ClientPageRedirectException(Common.REDIRECT_VIEW);
63
64             }
65         } catch (NullPointerException JavaDoc ex) {
66             throw new ClientPageRedirectException(Common.REDIRECT_INDEX);
67
68         } catch (Exception JavaDoc ex) {
69             writeDebugMsg("System error finding user: " + ex.getMessage());
70             throw new EnhydraPimPresentationException("System error finding user", ex);
71         }
72     }
73
74     /**
75      * handle throw exception event.
76      *
77      * @return html document
78      * @exception Exception
79      */

80     public XMLObject handleThrowException() throws Exception JavaDoc {
81         throw new Exception JavaDoc("This is a test exception thrown from Login.java handleThrowException()");
82     }
83
84     /**
85      * Display Error.html page
86      *
87      * @return html document
88      */

89     public XMLObject showErrorPage(String JavaDoc errorText) {
90         ErrorHTML errPage = (ErrorHTML) myComms.xmlcFactory.create(ErrorHTML.class);
91         if (errorText != null) {
92             errPage.setTextErrorText(errorText);
93         }
94         return errPage;
95     }
96
97     /**
98      * Display Index.html page
99      *
100      * @return html document
101      */

102     public XMLObject showIndexPage() {
103         return (IndexHTML) myComms.xmlcFactory.create(IndexHTML.class);
104     }
105
106 }
Popular Tags