1 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 21 public class Login extends BasePO { 22 23 private static final String LOGIN_USERNAME = "username"; 24 25 private static final String LOGIN_PASSWORD = "password"; 26 27 30 public boolean loggedInUserRequired() { 31 return false; 32 } 33 34 37 public XMLObject handleDefault() throws HttpPresentationException { 38 return showIndexPage(); 39 } 40 41 47 public XMLObject handleLogin() throws HttpPresentationException { 48 String username = this.getComms().request.getParameter(LOGIN_USERNAME); 49 String 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 } else { 61 this.setUser(user); 62 throw new ClientPageRedirectException(Common.REDIRECT_VIEW); 63 64 } 65 } catch (NullPointerException ex) { 66 throw new ClientPageRedirectException(Common.REDIRECT_INDEX); 67 68 } catch (Exception ex) { 69 writeDebugMsg("System error finding user: " + ex.getMessage()); 70 throw new EnhydraPimPresentationException("System error finding user", ex); 71 } 72 } 73 74 80 public XMLObject handleThrowException() throws Exception { 81 throw new Exception ("This is a test exception thrown from Login.java handleThrowException()"); 82 } 83 84 89 public XMLObject showErrorPage(String 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 102 public XMLObject showIndexPage() { 103 return (IndexHTML) myComms.xmlcFactory.create(IndexHTML.class); 104 } 105 106 } | Popular Tags |