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: MessengerLogin.java,v 1.1 2006-09-11 12:29:26 sinisa Exp $
018: */
019:
020: package com.lutris.airsent.presentation.messenger;
021:
022: import com.lutris.appserver.server.httpPresentation.*;
023: import com.lutris.appserver.server.session.*;
024: import com.lutris.util.*; //import com.lutris.xml.xmlc.*;
025: import org.enhydra.xml.xmlc.XMLCUtil;
026: import org.w3c.dom.*;
027: import org.enhydra.xml.xmlc.XMLObject;
028: import java.util.Date;
029: import com.lutris.airsent.presentation.AirSentPresentationException;
030: import com.lutris.airsent.presentation.AirSentConstants;
031: import com.lutris.airsent.presentation.DeviceBasePO;
032: import com.lutris.airsent.presentation.DeviceUtils;
033: import com.lutris.airsent.spec.messenger.Messenger;
034: import java.lang.reflect.Method;
035:
036: /**
037: * MessengerLogin.java handles the login functionality for
038: * the messenger of the AirSent app.
039: *
040: * @author
041: * @version
042: */
043: public class MessengerLogin extends DeviceBasePO {
044:
045: /**
046: * Constants
047: */
048: private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER;
049:
050: /**
051: * Superclass method override.
052: * returns the authorization level necessary to access this po.
053: *
054: * @return int required authorization level
055: */
056: public int getRequiredAuthLevel() {
057: return AUTH_LEVEL;
058: }
059:
060: /**
061: * Default event. Just show the page.
062: *
063: * @return XMLObject document
064: * @exception HttpPresentationException
065: */
066: public XMLObject handleDefault() throws HttpPresentationException {
067: return showPage(null);
068: }
069:
070: /**
071: * Displays the MessengerLogin page.
072: *
073: * @param errorMsg, the error messages
074: * @return wml document
075: * @exception HttpPresentationException
076: */
077: public XMLObject showPage(String errorMsg)
078:
079: throws HttpPresentationException {
080: Class tempClass = null;
081: Object page = null;
082: Method setTextErrorText = null;
083: Method getTagErrorText = null;
084:
085: try {
086: Class stringClass = Class.forName("java.lang.String");
087: tempClass = Class
088: .forName(DeviceUtils
089: .getPageName(myComms,
090: "com.lutris.airsent.presentation.messenger.MessengerLogin"));
091: page = myComms.xmlcFactory.create(tempClass);
092: Class[] argTypeArr = { stringClass };
093: setTextErrorText = tempClass.getMethod("setTextErrorText",
094: argTypeArr);
095: getTagErrorText = tempClass.getMethod(
096: "getElementErrorText", null);
097: } catch (Exception e) {
098: }
099:
100: // MessengerLoginPage page =
101: // (MessengerLoginPage) create("com.lutris.airsent.presentation.messenger.MessengerLogin");
102:
103: try {
104: Element error = (Element) getTagErrorText
105: .invoke(page, null);
106: // Element error = page.getTagErrorText();
107:
108: if (null != errorMsg
109: || null != (errorMsg = this .getSessionData()
110: .getAndClearUserMessage())) {
111:
112: Object[] temp = { errorMsg };
113: setTextErrorText.invoke(page, temp);
114: //page.setTextErrorText(errorMsg);
115: } else {
116: Object[] temp = { "" };
117: setTextErrorText.invoke(page, temp);
118: //page.setTextErrorText("");
119: }
120:
121: // Add a jsession key for those who requset it:
122: // Like the java client app.
123: if (error.getAttributeNode("jsessionid") != null) {
124: error.getAttributeNode("jsessionid").setValue(
125: myComms.session.getSessionKey());
126: }
127: } catch (Exception ex) {
128: throw new AirSentPresentationException(
129: "Error in messenger login", ex);
130: }
131: DeviceUtils.setURLTimeStamp((XMLObject) page);
132: return ((XMLObject) page);
133: }
134:
135: /**
136: * Process login data
137: *
138: * @return error String
139: */
140: public XMLObject handleLogin() throws HttpPresentationException {
141: String badge = myComms.request
142: .getParameter(AirSentConstants.LOGIN_NAME);
143: String password = myComms.request
144: .getParameter(AirSentConstants.PASSWORD_NAME);
145: Messenger messenger = null;
146:
147: try {
148: if (badge == null
149: || password == null
150: || (messenger = getApplication().getHomeManager()
151: .getMessengerManager().validatePassword(
152: badge, password)) == null) {
153: return showPage("Invalid login or password!!");
154: } else {
155:
156: getSessionData().setMessenger(messenger);
157: getSessionData().setUserAuth(
158: AirSentConstants.MESSENGER_USER);
159: throw new ClientPageRedirectException(
160: AirSentConstants.MESSENGER_MAIN_PAGE);
161:
162: }
163: } catch (Exception ex) {
164: throw new AirSentPresentationException(
165: "System error logging in Messenger.", ex);
166: }
167:
168: }
169:
170: }
|