1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package olr.presentation;
20
21 import org.apache.log4j.Logger;
22
23 import olr.om.RdfUser;
24 import olr.om.RdfUserPeer;
25
26 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
27 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
28
29 public class Login extends ExtendedHttpPresentation {
30
31 public boolean loggedInUserRequired()
32 {
33 return false;
34 }
35
36 public String handleDefault()
37 throws HttpPresentationException
38 {
39 if(getUser() != null)
40 throw new ClientPageRedirectException("Welcome1.po");
41 else
42 return showPage();
43 }
44
45 public String handleLogout() throws HttpPresentationException
46 {
47 if(getUser() != null)
48 try
49 {
50 getSessionData().clearLock();
51 clearSession();
52 }
53 catch(Exception e)
54 {
55 throw new HttpPresentationException(e);
56 }
57
58 return showPage();
59 }
60
61 public String handleLogin()
62 throws HttpPresentationException
63 {
64 String login = getComms().request.getParameter(LOGIN_NAME);
65 String password = getComms().request.getParameter(PASSWORD_NAME);
66 RdfUser user = null;
67 try
68 {
69 try
70 {
71 user = RdfUserPeer.getUser(login, password);
72 }
73 catch(Exception e)
74 {
75 String s1 = showPage(e.getMessage());
76 return s1;
77 }
78 if(user == null)
79 {
80 String s = showPage("Incorrect username/password combination!");
81 return s;
82 } else
83 {
84 setUser(user);
85 throw new ClientPageRedirectException("Welcome1.po");
86 }
87 }
88 catch(Exception ex)
89 {
90 Logger.getLogger(getClass()).debug("System error finding user: ".concat(String.valueOf(String.valueOf(ex.getMessage()))));
91 throw new HttpPresentationException("System error finding user", ex);
92 }
93 }
94
95 public String showPage()
96 {
97 return showPage(null);
98 }
99
100 public String showPage(String errorMsg)
101 {
102 LoginHTML page = new LoginHTML();
103 if(errorMsg != null)
104 page.setTextErrorText(errorMsg);
105 return page.toDocument();
106 }
107
108 private static String LOGIN_NAME = "login";
109 private static String PASSWORD_NAME = "password";
110
111 }