KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > poker > presentation > login > LoginProcessorPresentation


1 package poker.presentation.login;
2
3 import java.io.*;
4 import java.net.*;
5 import com.lutris.http.*;
6 import com.lutris.appserver.server.httpPresentation.*;
7 import com.lutris.appserver.server.user.*;
8 import com.lutris.util.*;
9 import poker.spec.*;
10 import poker.Poker;
11
12 /**
13  * Presentation Object that processes the login request and redirects
14  * to the appropriate page.
15  *
16  *
17  * EnhyDraw!, beta 4, 5/21/99
18  *
19  * Copyright 1999, Larry Wolcot & Daryl Tempesta
20  * ALL rights reserved. Not for commercial use
21  * without written permission from both authors.
22  *
23  * @author Shawn McMurdo, Larry Wolcott
24  * @version $Revision: 1.1 $
25  */

26 public class LoginProcessorPresentation implements HttpPresentation{
27
28
29     private GameManager gameManager;
30     private final String JavaDoc homePage = "main/PlaceBetPresentation.po";
31     private final String JavaDoc loginPage = "login/LoginPresentation.po";
32     private final String JavaDoc debugArg = "debug";
33     private final String JavaDoc helpArg = "help";
34
35   public void run(HttpPresentationComms comms) throws Exception JavaDoc {
36
37     Poker application = (Poker)comms.application;
38     gameManager = application.getGameManager();
39
40     String JavaDoc username = comms.request.getParameter("username");
41     String JavaDoc pw = comms.request.getParameter("pw");
42     String JavaDoc cashAsString = comms.request.getParameter("cash");
43
44     String JavaDoc redirect = loginPage + "?" + "pw=" + pw + "&" +
45                                         "username=" + username + "&" +
46                                         "cash=" + cashAsString;
47
48     if( username==null || pw==null ) {
49         comms.session.getSessionData().set("loginMessage",
50                       "You must specify a username and password to login.");
51         throw new ClientPageRedirectException(
52                   comms.request.getAppFileURIPath(redirect));
53     }
54
55     int cash = 0;
56     if(cashAsString != null && !cashAsString.equals("")) {
57       try {
58        cash = Integer.parseInt(cashAsString);
59       }
60       catch( NumberFormatException JavaDoc e ) {
61         comms.session.getSessionData().set("loginMessage",
62                                             "Invalid input in cash field!");
63         throw new ClientPageRedirectException(
64                   comms.request.getAppFileURIPath(redirect));
65       }
66     }
67
68     if( cash < 0 || cash > 1000000 ) {
69         comms.session.getSessionData().set("error",
70                       "Cash amount can't be negative or greather than 1000000!");
71         throw new ClientPageRedirectException(
72                   comms.request.getAppFileURIPath(redirect));
73     }
74
75  
76
77     boolean auth = false;
78     
79 /*
80  * Catch Null pointer exception ( we canot make a instances of classes from business layer when we run poker_pres )
81  * We need to allow poker_pres to be dynamic , so if the requested url is /poker_pres/..... user dont need to be logged
82  */

83
84 try{
85     if ((!username.equals("")) && (!pw.equals(""))){
86        auth = gameManager.authenticate(username, pw);
87     }
88
89     if (!auth){
90       comms.session.getSessionData().set("loginMessage",
91                                           "Invalid username or password.");
92        //comms.session.getSessionData().set("oname", username);
93
}
94     else {
95       PokerGame game = (PokerGame)gameManager.getGame(username);
96       game.setCash(game.getCash()+cash);
97       comms.session.setUser((User)game.getPlayer());
98       comms.session.getSessionData().set("game", game);
99       redirect = homePage;
100     }
101
102     
103 }catch (NullPointerException JavaDoc e){
104     
105   
106    throw new ClientPageRedirectException(
107               comms.request.getAppFileURIPath(homePage));
108
109 }
110   throw new ClientPageRedirectException(
111               comms.request.getAppFileURIPath(redirect));
112   
113   }
114
115 }
116
Popular Tags