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:47:00 sinisa Exp $
022: */
023:
024: package transactionsDiscRack.presentation.personMgmt;
025:
026: import transactionsDiscRack.spec.*;
027: import transactionsDiscRack.presentation.BasePO;
028: import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException;
029:
030: import com.lutris.appserver.server.httpPresentation.*;
031: import org.enhydra.xml.xmlc.XMLObject;
032:
033: /**
034: * Login.java handles the login functionality of the DiscRack app.
035: *
036: */
037: public class Login extends BasePO {
038:
039: /**
040: * Constants
041: */
042: private static String LOGIN_NAME = "login";
043:
044: private static String PASSWORD_NAME = "password";
045:
046: /**
047: * Superclass method override
048: */
049: public boolean loggedInUserRequired() {
050: return false;
051: }
052:
053: /**
054: * Default event. Just show the page.
055: */
056: public XMLObject handleDefault() throws HttpPresentationException {
057: return showPage(null);
058: }
059:
060: /**
061: * Process login data
062: *
063: * @return wml document
064: * @exception HttpPresentationException
065: */
066: public XMLObject handleLogin() throws HttpPresentationException {
067: String login = this .getComms().request.getParameter(LOGIN_NAME);
068: String password = this .getComms().request
069: .getParameter(PASSWORD_NAME);
070:
071: /*
072: * Catch Null pointer exception ( we canot make a instances of classes
073: * from business layer when we run discRack_pres ) We need to allow
074: * presentation module to be functional , to allow users who run
075: * discRack_pres response will be default HTML page
076: */
077: try {
078:
079: Person user = ((PersonGenerator) PersonGeneratorFactory
080: .getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl"))
081: .findPerson(login, this .transaction);
082: if (null == user || !user.getPassword().equals(password)) {
083: return showPage("Invalid username or password");
084: // Show error message that user not found (bad
085: // username/password)
086: } else {
087: this .setUser(user);
088: throw new ClientPageRedirectException(
089: getComms().request.getApplicationPath()
090: + DISC_CATALOG_PAGE);
091: }
092: } catch (TransactionsDiscRackException ex) {
093: writeDebugMsg("System error finding user: "
094: + ex.getMessage());
095: throw new TransactionsDiscRackPresentationException(
096: "System error finding user", ex);
097: } catch (Exception ex) {
098: // securte presentation mode response
099: throw new ClientPageRedirectException(getComms().request
100: .getApplicationPath()
101: + DISC_CATALOG_PAGE);
102: }
103: }
104:
105: /**
106: * handle logout event
107: *
108: * @return html document
109: * @exception HttpPresentationException
110: */
111: public XMLObject handleLogout() throws HttpPresentationException {
112: this .removeUserFromSession();
113: return (ExitHTML) myComms.xmlcFactory.create(ExitHTML.class);
114: }
115:
116: /**
117: * handle throw exception event.
118: *
119: * @return html document
120: * @exception Exception
121: */
122: public XMLObject handleThrowException() throws Exception {
123: throw new Exception(
124: "This is a test exception thrown from Login.java handleThrowException()");
125: }
126:
127: /**
128: * display page
129: *
130: * @param errorMsg
131: * the error messages
132: * @return html document
133: */
134: public XMLObject showPage(String errorMsg) {
135:
136: LoginHTML page = (LoginHTML) myComms.xmlcFactory
137: .create(LoginHTML.class);
138:
139: if (null != errorMsg
140: || null != (errorMsg = this.getSessionData()
141: .getAndClearUserMessage())) {
142: page.setTextErrorText(errorMsg);
143: } else {
144: page.getElementErrorText().getParentNode().removeChild(
145: page.getElementErrorText());
146: }
147:
148: return page;
149: }
150: }
|