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 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 23 public class Login extends BasePO { 24 25 28 private static String LOGIN_NAME = "login"; 29 private static String PASSWORD_NAME = "password"; 30 private static String INDEX_PAGE = "Index.po"; 31 32 35 protected int getRequiredAuthLevel() { 36 return 0; 37 } 38 39 42 public XMLObject handleDefault() 43 throws HttpPresentationException { 44 return showPage(null); 45 } 46 47 53 public XMLObject handleLogin() 54 throws HttpPresentationException { 55 String login = this.getComms().request.getParameter(LOGIN_NAME); 56 String 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 } else { 74 this.setUser(user); 75 throw new ClientPageRedirectException(INDEX_PAGE); 76 } 77 82 }catch(NullPointerException 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 98 public XMLObject showPage(String 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 |