001: /*
002: * Copyright (c) 1999-2001 Lutris Technologies, Inc. All Rights
003: * Reserved.
004: *
005: * This source code file is distributed by Lutris Technologies, Inc. for
006: * use only by licensed users of product(s) that include this source
007: * file. Use of this source file or the software that uses it is covered
008: * by the terms and conditions of the Lutris Enhydra Development License
009: * Agreement included with this product.
010: *
011: * This Software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
012: * ANY KIND, either express or implied. See the License for the specific terms
013: * governing rights and limitations under the License.
014: *
015: * Contributor(s):
016: *
017: * $Id: Login.java,v 1.1 2006-09-11 12:29:26 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation.customer;
021:
022: import com.lutris.airsent.presentation.BasePO;
023: import com.lutris.appserver.server.httpPresentation.*;
024: import com.lutris.appserver.server.session.*;
025: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
026: //import com.lutris.xml.xmlc.html.*;
027: import org.w3c.dom.*;
028: import org.w3c.dom.html.*;
029: import org.enhydra.xml.xmlc.XMLObject;
030: import com.lutris.airsent.spec.AirSentException;
031:
032: import com.lutris.airsent.presentation.AirSentPresentationException;
033: import com.lutris.airsent.presentation.AirSentConstants;
034: import java.util.*;
035: import com.lutris.airsent.spec.customer.Customer;
036:
037: /**
038: * The login page of the AirSent app
039: *
040: */
041: public class Login extends BasePO {
042:
043: /**
044: * Constants
045: */
046: private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER;
047:
048: /**
049: * Superclass method override.
050: * returns the authorization level necessary to access this po.
051: *
052: * @return int required authorization level
053: */
054: public int getRequiredAuthLevel() {
055: return AUTH_LEVEL;
056: }
057:
058: /**
059: * Default event. Just show the page.
060: */
061: public XMLObject handleDefault() throws HttpPresentationException {
062: return showPage(null);
063: }
064:
065: /**
066: *
067: * @param error messages
068: * @return page as XMLObject.
069: */
070: public XMLObject showPage(String errorMsg)
071: throws AirSentPresentationException {
072: LoginHTML page = (LoginHTML) myComms.xmlcFactory
073: .create(LoginHTML.class);
074:
075: try {
076: if (null != errorMsg
077: || null != (errorMsg = getSessionData()
078: .getAndClearUserMessage())) {
079: page.setTextErrorText(errorMsg);
080: } else {
081: page.getElementErrorText().getParentNode().removeChild(
082: page.getElementErrorText());
083: }
084: } catch (Exception e) {
085: throw new AirSentPresentationException(
086: "Trouble showing page", e);
087: }
088:
089: return page;
090: }
091:
092: /**
093: * Process login data
094: *
095: * @return error String
096: */
097: public XMLObject handleLogin() throws HttpPresentationException {
098: String login = getComms().request
099: .getParameter(AirSentConstants.LOGIN_NAME);
100: String password = getComms().request
101: .getParameter(AirSentConstants.PASSWORD_NAME);
102: Customer customer = null;
103:
104: try {
105: if ((customer = getApplication().getHomeManager()
106: .getCustomerManager().validatePassword(login,
107: password)) == null) {
108: return showPage("Invalid username or password.");
109: } else {
110: getSessionData().setCustomer(customer);
111: getSessionData().setUserAuth(
112: AirSentConstants.CUSTOMER_USER);
113:
114: this .getSessionData().setUserMessage(
115: "Welcome, " + customer.getFirstName());
116: //throw new ServerPageRedirectException(AirSentConstants.ORDERSTEP1_PO);
117: throw new ClientPageRedirectException(
118: AirSentConstants.ORDERSTEP1_PO);
119: }
120: /*
121: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run AirSent_pres )
122: * We need to allow AirSent_pres to be functional , response
123: * will be default HTML page
124: *
125: */
126: } catch (NullPointerException ex) {
127: throw new ClientPageRedirectException(
128: AirSentConstants.ORDERSTEP1_PO);
129:
130: } catch (Exception ex) {
131: throw new AirSentPresentationException(
132: "System error finding user", ex);
133: }
134: }
135:
136: }
|