001: package poker.presentation.login;
002:
003: import java.io.*;
004: import java.net.*;
005: import com.lutris.http.*;
006: import com.lutris.appserver.server.httpPresentation.*;
007: import com.lutris.appserver.server.user.*;
008: import com.lutris.util.*;
009: import poker.spec.*;
010: import poker.Poker;
011:
012: /**
013: * Presentation Object that processes the login request and redirects
014: * to the appropriate page.
015: *
016: *
017: * EnhyDraw!, beta 4, 5/21/99
018: *
019: * Copyright 1999, Larry Wolcot & Daryl Tempesta
020: * ALL rights reserved. Not for commercial use
021: * without written permission from both authors.
022: *
023: * @author Shawn McMurdo, Larry Wolcott
024: * @version $Revision: 1.1 $
025: */
026: public class LoginProcessorPresentation implements HttpPresentation {
027:
028: private GameManager gameManager;
029: private final String homePage = "main/PlaceBetPresentation.po";
030: private final String loginPage = "login/LoginPresentation.po";
031: private final String debugArg = "debug";
032: private final String helpArg = "help";
033:
034: public void run(HttpPresentationComms comms) throws Exception {
035:
036: Poker application = (Poker) comms.application;
037: gameManager = application.getGameManager();
038:
039: String username = comms.request.getParameter("username");
040: String pw = comms.request.getParameter("pw");
041: String cashAsString = comms.request.getParameter("cash");
042:
043: String redirect = loginPage + "?" + "pw=" + pw + "&"
044: + "username=" + username + "&" + "cash=" + cashAsString;
045:
046: if (username == null || pw == null) {
047: comms.session
048: .getSessionData()
049: .set("loginMessage",
050: "You must specify a username and password to login.");
051: throw new ClientPageRedirectException(comms.request
052: .getAppFileURIPath(redirect));
053: }
054:
055: int cash = 0;
056: if (cashAsString != null && !cashAsString.equals("")) {
057: try {
058: cash = Integer.parseInt(cashAsString);
059: } catch (NumberFormatException e) {
060: comms.session.getSessionData().set("loginMessage",
061: "Invalid input in cash field!");
062: throw new ClientPageRedirectException(comms.request
063: .getAppFileURIPath(redirect));
064: }
065: }
066:
067: if (cash < 0 || cash > 1000000) {
068: comms.session
069: .getSessionData()
070: .set("error",
071: "Cash amount can't be negative or greather than 1000000!");
072: throw new ClientPageRedirectException(comms.request
073: .getAppFileURIPath(redirect));
074: }
075:
076: boolean auth = false;
077:
078: /*
079: * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
080: * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... user dont need to be logged
081: */
082:
083: try {
084: if ((!username.equals("")) && (!pw.equals(""))) {
085: auth = gameManager.authenticate(username, pw);
086: }
087:
088: if (!auth) {
089: comms.session.getSessionData().set("loginMessage",
090: "Invalid username or password.");
091: //comms.session.getSessionData().set("oname", username);
092: } else {
093: PokerGame game = (PokerGame) gameManager
094: .getGame(username);
095: game.setCash(game.getCash() + cash);
096: comms.session.setUser((User) game.getPlayer());
097: comms.session.getSessionData().set("game", game);
098: redirect = homePage;
099: }
100:
101: } catch (NullPointerException e) {
102:
103: throw new ClientPageRedirectException(comms.request
104: .getAppFileURIPath(homePage));
105:
106: }
107: throw new ClientPageRedirectException(comms.request
108: .getAppFileURIPath(redirect));
109:
110: }
111:
112: }
|