/* -----------------------------------------------------------------------------
* Copyright (c) 2001, Low Kin Onn
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither name of the Scioworks Pte. Ltd. nor the names of its contributors
* may beused to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* -----------------------------------------------------------------------------
*/
package scioworks.imap.presentation;
import com.lutris.appserver.server.httpPresentation.*;
import org.w3c.dom.*;
import org.w3c.dom.html.*;
import scioworks.imap.presentation.imapWeb.*;
import scioworks.imap.presentation.base.BasePO;
import scioworks.imap.presentation.security.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class loginAction extends BasePO {
// Override login requirement
protected boolean isLoginRequired() {
return false;
}
private String login(String username, String password)
throws HttpPresentationException {
DefaultEmailLogin login = new DefaultEmailLogin(username,password);
try {
//We need to allow imapWeb_pres to be functional , so if the requested url is imapWeb_pres we dont try to connect to server
//to see default HTML pages
String uri = m_comms.request.getRequestURI();
boolean is= uri.startsWith("/imapWeb_pres");
if(is)
super.getImapWebSessionData().setImapSession(Session.getDefaultInstance(System.getProperties(),null));
// try to login
else{
login.login();
super.getImapWebSessionData().setImapURL(login.getSessionData().getImapURL());
super.getImapWebSessionData().setImapSession(login.getSessionData().getImapSession());
super.getImapWebSessionData().setImapStore(login.getSessionData().getImapStore());
}
} catch (ACLException e) {
// failed to login
return this.showPage(e.getMessage());
}
welcomeHTML page = (welcomeHTML)m_comms.xmlcFactory.create(welcomeHTML.class);
return page.toDocument();
}
public String handleDefault()
throws ServerPageRedirectException, HttpPresentationException {
String pUsername = getStringParameter(PARAM_username);
String pPassword = getStringParameter(PARAM_password);
String pEvent = getStringParameter(PARAM_event);
if (pEvent.equals(EVENT_login)) {
return login(pUsername, pPassword);
} else {
return showPage(null);
}
}
public String showPage(String errorMsg) {
loginHTML page = (loginHTML)m_comms.xmlcFactory.create(loginHTML.class);
//First priority: try to use the passed-in error message
// Second priority: try to use the session data's error message
// If there are no error messages then clear the prototype error text
if(null != errorMsg ||
null != (errorMsg = this.getImapWebSessionData().getAndClearUserMessage())) {
page.setTextErrorText(errorMsg);
} else {
page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText());
}
return page.toDocument();
}
}
|