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: AdminLogin.java,v 1.1 2006-09-11 12:29:11 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation.admin;
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:
031: import com.lutris.airsent.spec.AirSentException;
032:
033: import com.lutris.airsent.presentation.AirSentPresentationException;
034: import com.lutris.airsent.presentation.AirSentConstants;
035: import java.util.*;
036: import com.lutris.airsent.spec.messenger.Messenger;
037:
038: /**
039: * The login page for the Admin of the AirSent app
040: *
041: */
042: public class AdminLogin extends BasePO {
043:
044: /**
045: * Constants
046: */
047: private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER;
048:
049: /**
050: * Superclass method override.
051: * returns the authorization level necessary to access this po.
052: *
053: * @return int required authorization level
054: */
055: public int getRequiredAuthLevel() {
056: return AUTH_LEVEL;
057: }
058:
059: /**
060: * Default event. Just show the page.
061: */
062: public XMLObject handleDefault() throws HttpPresentationException {
063: return showPage(null);
064: }
065:
066: /**
067: * Shows the AdminLogin page
068: * @param error messages
069: * @return page.
070: */
071: public XMLObject showPage(String errorMsg)
072: throws AirSentPresentationException {
073: AdminLoginHTML page = (AdminLoginHTML) myComms.xmlcFactory
074: .create(AdminLoginHTML.class);
075:
076: try {
077: if (null != errorMsg
078: || null != (errorMsg = getSessionData()
079: .getAndClearUserMessage())) {
080: page.setTextErrorText(errorMsg);
081: } else {
082: page.getElementErrorText().getParentNode().removeChild(
083: page.getElementErrorText());
084: }
085: } catch (Exception e) {
086: throw new AirSentPresentationException(
087: "Trouble showing page", e);
088: }
089:
090: return page;
091: }
092:
093: /**
094: * Handles the handleLogin event.
095: *
096: * @return error String
097: */
098: public XMLObject handleLogin() throws HttpPresentationException {
099: String login = getComms().request
100: .getParameter(AirSentConstants.LOGIN_NAME);
101: String password = getComms().request
102: .getParameter(AirSentConstants.PASSWORD_NAME);
103: Messenger messenger = null;
104:
105: try {
106: if ((messenger = getApplication().getHomeManager()
107: .getMessengerManager().validatePassword(login,
108: password)) == null) {
109: return showPage("Invalid username or password.");
110: } else {
111: getSessionData().setMessenger(messenger);
112: getSessionData().setUserAuth(
113: AirSentConstants.ADMINISTRATOR_USER);
114:
115: throw new ClientPageRedirectException(
116: AirSentConstants.ADMIN_MAIN_PAGE);
117: }
118:
119: //We need to allow AirSent_pres to be functional , response will be default HTML page
120: } catch (NullPointerException e) {
121: // throw new ClientPageRedirectException(AirSentConstants.ADMIN_MAIN_PAGE);
122: AdminMainHTML defaultPage = (AdminMainHTML) myComms.xmlcFactory
123: .create(AdminMainHTML.class);
124: defaultPage.setTextErrorText("This is a default HTML page");
125: return defaultPage;
126:
127: } catch (Exception ex) {
128: throw new AirSentPresentationException(
129: "System error finding user", ex);
130: }
131: }
132:
133: }
|