001: package projectmanagement.presentation;
002:
003: import projectmanagement.spec.employee.*;
004: import projectmanagement.spec.*;
005: import projectmanagement.ProjectManagement;
006: import com.lutris.appserver.server.httpPresentation.*;
007: import com.lutris.appserver.server.session.*;
008: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
009: //import com.lutris.xml.xmlc.html.*;
010: import org.w3c.dom.*;
011: import org.w3c.dom.html.*;
012: import org.enhydra.xml.xmlc.XMLObject;
013: import projectmanagement.spec.ProjectManagementException;
014: import projectmanagement.presentation.ProjectManagementPresentationException;
015:
016: /**
017: * Login.java handles the login functionality of the ProjectManagement app.
018: *
019: * @author Sasa Bojanic
020: * @version 1.0
021: */
022: public class Login extends BasePO {
023:
024: /**
025: * Constants
026: */
027: private static String LOGIN_NAME = "login";
028: private static String PASSWORD_NAME = "password";
029: private static String INDEX_PAGE = "Index.po";
030:
031: /**
032: * Superclass method override. Returns 0.
033: */
034: protected int getRequiredAuthLevel() {
035: return 0;
036: }
037:
038: /**
039: * Default event. Just show the page.
040: */
041: public XMLObject handleDefault() throws HttpPresentationException {
042: return showPage(null);
043: }
044:
045: /**
046: * Process login data
047: *
048: * @return wml document
049: * @exception HttpPresentationException
050: */
051: public XMLObject handleLogin() throws HttpPresentationException {
052: String login = this .getComms().request.getParameter(LOGIN_NAME);
053: String password = this .getComms().request
054: .getParameter(PASSWORD_NAME);
055: Employee user = null;
056:
057: ProjectManagement pm = getApplication();
058: boolean isAdmin = false;
059: if (pm.getAdminUsername().equals(login)
060: && pm.getAdminPassword().equals(password)) {
061: isAdmin = true;
062: }
063: this .getSessionData().setAdmin(isAdmin);
064: try {
065:
066: EmployeeManager employeeManager = EmployeeManagerFactory
067: .getEmployeeManager("projectmanagement.business.employee.EmployeeManagerImpl");
068: user = employeeManager.findEmployee(login);
069:
070: if (!isAdmin
071: && (null == user || !user.getPassword().equals(
072: password))) {
073: return showPage("Invalid username or password");
074: // Show error message that user not found (bad username/password)
075: } else {
076: this .setUser(user);
077: throw new ClientPageRedirectException(INDEX_PAGE);
078: }
079: /*
080: * We need to allow ProjectManagement_pres to be functional , we must allow user to acsses next page if he run ProjectManagement_pres
081: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run ProjectManagement_pres )
082: *
083: */
084: } catch (NullPointerException e) {
085: throw new ClientPageRedirectException(INDEX_PAGE);
086:
087: } catch (ProjectManagementException ex) {
088: this .writeDebugMsg("System error finding user: "
089: + ex.getMessage());
090: throw new ProjectManagementPresentationException(
091: "System error finding user", ex);
092:
093: }
094: }
095:
096: /**
097: * display page
098: *
099: * @param errorMsg, the error messages
100: * @return html document
101: */
102: public XMLObject showPage(String errorMsg) {
103:
104: LoginHTML page = new LoginHTML();
105:
106: if (null != errorMsg
107: || null != (errorMsg = this.getSessionData()
108: .getAndClearUserMessage())) {
109: page.setTextLblErrorText(errorMsg);
110: } else {
111: page.getElementLblErrorText().getParentNode().removeChild(
112: page.getElementLblErrorText());
113: }
114:
115: return page;
116: }
117: }
|