001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: Login.java,v 1.1 2006-09-11 12:32:06 sinisa Exp $
022: */
023:
024: package discRack.presentation.personMgmt;
025:
026: import discRack.spec.*;
027: import discRack.presentation.BasePO;
028: import discRack.presentation.DiscRackPresentationException;
029:
030: import com.lutris.appserver.server.httpPresentation.*;
031: import com.lutris.appserver.server.session.*;
032: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
033: //import com.lutris.xml.xmlc.html.*;
034: import org.w3c.dom.*;
035: import org.w3c.dom.html.*;
036: import org.enhydra.xml.xmlc.XMLObject;
037:
038: /**
039: * Login.java handles the login functionality of the DiscRack app.
040: *
041: * @author
042: * @version
043: */
044: public class Login extends BasePO {
045:
046: /**
047: * Constants
048: */
049: private static String SUBMIT_NAME = "submit";
050: private static String LOGIN_NAME = "login";
051: private static String PASSWORD_NAME = "password";
052: private static String ERROR_NAME = "ERROR_NAME";
053:
054: /**
055: * Superclass method override
056: */
057: public boolean loggedInUserRequired() {
058: return false;
059: }
060:
061: /**
062: * Default event. Just show the page.
063: */
064: public XMLObject handleDefault() throws HttpPresentationException {
065: return showPage(null);
066: }
067:
068: /**
069: * Process login data
070: *
071: * @return wml document
072: * @exception HttpPresentationException
073: */
074: public XMLObject handleLogin() throws HttpPresentationException {
075: String login = this .getComms().request.getParameter(LOGIN_NAME);
076: String password = this .getComms().request
077: .getParameter(PASSWORD_NAME);
078:
079: Person user = null;
080:
081: /*
082: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run discRack_pres )
083: * We need to allow discRack_pres to be functional , to allow users who run discRack_pres response
084: * will be default HTML page
085: */
086:
087: try {
088:
089: user = ((PersonGenerator) PersonGeneratorFactory
090: .getPersonGenerator("discRack.business.person.PersonGeneratorImpl"))
091: .findPerson(login);
092:
093: if (null == user || !user.getPassword().equals(password)) {
094: return showPage("Invalid username or password");
095: // Show error message that user not found (bad username/password)
096: } else {
097: this .setUser(user);
098: throw new ClientPageRedirectException(
099: getComms().request.getApplicationPath()
100: + DISC_CATALOG_PAGE);
101: }
102: } catch (NullPointerException ex) {
103:
104: throw new ClientPageRedirectException(getComms().request
105: .getApplicationPath()
106: + DISC_CATALOG_PAGE);
107:
108: } catch (DiscRackException ex) {
109: this .writeDebugMsg("System error finding user: "
110: + ex.getMessage());
111: throw new DiscRackPresentationException(
112: "System error finding user", ex);
113: }
114: }
115:
116: /**
117: * handle logout event
118: *
119: * @return html document
120: * @exception HttpPresentationException
121: */
122: public XMLObject handleLogout() throws HttpPresentationException {
123: this .removeUserFromSession();
124: return (ExitHTML) myComms.xmlcFactory.create(ExitHTML.class);
125: // return new ExitHTML();
126: }
127:
128: /**
129: * handle throw exception event.
130: *
131: * @return html document
132: * @exception Exception
133: */
134: public XMLObject handleThrowException() throws Exception {
135: throw new Exception(
136: "This is a test exception thrown from Login.java handleThrowException()");
137: }
138:
139: /**
140: * display page
141: *
142: * @param errorMsg, the error messages
143: * @return html document
144: */
145: public XMLObject showPage(String errorMsg) {
146:
147: LoginHTML page = (LoginHTML) myComms.xmlcFactory
148: .create(LoginHTML.class);
149:
150: if (null != errorMsg
151: || null != (errorMsg = this.getSessionData()
152: .getAndClearUserMessage())) {
153: page.setTextErrorText(errorMsg);
154: } else {
155: page.getElementErrorText().getParentNode().removeChild(
156: page.getElementErrorText());
157: }
158:
159: return page;
160: }
161: }
|