KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > projectmanagement > presentation > Login


1 package projectmanagement.presentation;
2
3 import projectmanagement.spec.employee.*;
4 import projectmanagement.spec.*;
5 import projectmanagement.ProjectManagement;
6 import com.lutris.appserver.server.httpPresentation.*;
7 import com.lutris.appserver.server.session.*;
8 import com.lutris.util.*;
9 //import com.lutris.xml.xmlc.*;
10
//import com.lutris.xml.xmlc.html.*;
11
import org.w3c.dom.*;
12 import org.w3c.dom.html.*;
13 import org.enhydra.xml.xmlc.XMLObject;
14 import projectmanagement.spec.ProjectManagementException;
15 import projectmanagement.presentation.ProjectManagementPresentationException;
16
17 /**
18  * Login.java handles the login functionality of the ProjectManagement app.
19  *
20  * @author Sasa Bojanic
21  * @version 1.0
22  */

23 public class Login extends BasePO {
24
25    /**
26     * Constants
27     */

28    private static String JavaDoc LOGIN_NAME = "login";
29    private static String JavaDoc PASSWORD_NAME = "password";
30    private static String JavaDoc INDEX_PAGE = "Index.po";
31
32    /**
33     * Superclass method override. Returns 0.
34     */

35    protected int getRequiredAuthLevel() {
36       return 0;
37    }
38
39    /**
40     * Default event. Just show the page.
41     */

42    public XMLObject handleDefault()
43          throws HttpPresentationException {
44       return showPage(null);
45    }
46
47    /**
48     * Process login data
49     *
50     * @return wml document
51     * @exception HttpPresentationException
52     */

53    public XMLObject handleLogin()
54          throws HttpPresentationException {
55       String JavaDoc login = this.getComms().request.getParameter(LOGIN_NAME);
56       String JavaDoc password = this.getComms().request.getParameter(PASSWORD_NAME);
57       Employee user = null;
58
59       ProjectManagement pm=getApplication();
60       boolean isAdmin=false;
61       if (pm.getAdminUsername().equals(login) && pm.getAdminPassword().equals(password)) {
62          isAdmin=true;
63       }
64       this.getSessionData().setAdmin(isAdmin);
65       try {
66      
67      EmployeeManager employeeManager = EmployeeManagerFactory.getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
68      user = employeeManager.findEmployee(login);
69      
70          if(!isAdmin && (null == user || !user.getPassword().equals(password))) {
71             return showPage("Invalid username or password");
72             // Show error message that user not found (bad username/password)
73
} else {
74             this.setUser(user);
75             throw new ClientPageRedirectException(INDEX_PAGE);
76          }
77 /*
78  * We need to allow ProjectManagement_pres to be functional , we must allow user to acsses next page if he run ProjectManagement_pres
79  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
80  *
81  */

82       }catch(NullPointerException JavaDoc e){
83       throw new ClientPageRedirectException(INDEX_PAGE);
84             
85       } catch(ProjectManagementException ex) {
86          this.writeDebugMsg("System error finding user: " + ex.getMessage());
87          throw new ProjectManagementPresentationException("System error finding user", ex);
88        
89     }
90    }
91
92    /**
93     * display page
94     *
95     * @param errorMsg, the error messages
96     * @return html document
97     */

98    public XMLObject showPage(String JavaDoc errorMsg) {
99
100        LoginHTML page = new LoginHTML();
101
102       if(null != errorMsg ||
103             null != (errorMsg = this.getSessionData().getAndClearUserMessage())) {
104          page.setTextLblErrorText(errorMsg);
105       } else {
106          page.getElementLblErrorText().getParentNode().removeChild(page.getElementLblErrorText());
107       }
108
109       return page;
110    }
111 }
112
113
114
Popular Tags