/*
* Enhydra Java Application Server Project
*
* The contents of this file are subject to the Enhydra Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License on
* the Enhydra web site ( http://www.enhydra.org/ ).
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific terms governing rights and limitations
* under the License.
*
* The Initial Developer of the Enhydra Application Server is Lutris
* Technologies, Inc. The Enhydra Application Server and portions created
* by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
* All Rights Reserved.
*
* Contributor(s):
*
* $Id: Login.java,v 1.1 2006-09-11 12:47:00 sinisa Exp $
*/
package transactionsDiscRack.presentation.personMgmt;
import transactionsDiscRack.spec.*;
import transactionsDiscRack.presentation.BasePO;
import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException;
import com.lutris.appserver.server.httpPresentation.*;
import org.enhydra.xml.xmlc.XMLObject;
/**
* Login.java handles the login functionality of the DiscRack app.
*
*/
public class Login extends BasePO {
/**
* Constants
*/
private static String LOGIN_NAME = "login";
private static String PASSWORD_NAME = "password";
/**
* Superclass method override
*/
public boolean loggedInUserRequired() {
return false;
}
/**
* Default event. Just show the page.
*/
public XMLObject handleDefault() throws HttpPresentationException {
return showPage(null);
}
/**
* Process login data
*
* @return wml document
* @exception HttpPresentationException
*/
public XMLObject handleLogin() throws HttpPresentationException {
String login = this.getComms().request.getParameter(LOGIN_NAME);
String password = this.getComms().request.getParameter(PASSWORD_NAME);
/*
* Catch Null pointer exception ( we canot make a instances of classes
* from business layer when we run discRack_pres ) We need to allow
* presentation module to be functional , to allow users who run
* discRack_pres response will be default HTML page
*/
try {
Person user = ((PersonGenerator) PersonGeneratorFactory
.getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl"))
.findPerson(login,this.transaction);
if (null == user || !user.getPassword().equals(password)) {
return showPage("Invalid username or password");
// Show error message that user not found (bad
// username/password)
} else {
this.setUser(user);
throw new ClientPageRedirectException(getComms().request
.getApplicationPath()
+ DISC_CATALOG_PAGE);
}
} catch (TransactionsDiscRackException ex) {
writeDebugMsg("System error finding user: " + ex.getMessage());
throw new TransactionsDiscRackPresentationException(
"System error finding user", ex);
} catch (Exception ex) {
// securte presentation mode response
throw new ClientPageRedirectException(getComms().request
.getApplicationPath()
+ DISC_CATALOG_PAGE);
}
}
/**
* handle logout event
*
* @return html document
* @exception HttpPresentationException
*/
public XMLObject handleLogout() throws HttpPresentationException {
this.removeUserFromSession();
return (ExitHTML) myComms.xmlcFactory.create(ExitHTML.class);
}
/**
* handle throw exception event.
*
* @return html document
* @exception Exception
*/
public XMLObject handleThrowException() throws Exception {
throw new Exception(
"This is a test exception thrown from Login.java handleThrowException()");
}
/**
* display page
*
* @param errorMsg
* the error messages
* @return html document
*/
public XMLObject showPage(String errorMsg) {
LoginHTML page = (LoginHTML) myComms.xmlcFactory
.create(LoginHTML.class);
if (null != errorMsg
|| null != (errorMsg = this.getSessionData()
.getAndClearUserMessage())) {
page.setTextErrorText(errorMsg);
} else {
page.getElementErrorText().getParentNode().removeChild(
page.getElementErrorText());
}
return page;
}
}
|