1 20 21 package golfShop.presentation.xmlc.login; 22 23 import java.io.*; 24 import java.net.*; 25 import java.util.*; 26 import com.lutris.http.*; 27 import com.lutris.appserver.server.httpPresentation.*; 28 import com.lutris.appserver.server.user.*; 29 import com.lutris.util.*; 30 import golfShop.GolfShop; 31 import golfShop.spec.user.*; 32 import com.lutris.appserver.server.session.*; 33 import golfShop.spec.LoginException; 34 41 public class LoginProcessor implements HttpPresentation { 42 45 private LoginState loginState; 46 47 private static final String nousername = 48 "You must specify a username and password to login."; 49 private static final String badlogin = 50 "Incorrect username or password."; 51 private static final String unknownhost = 52 "Login failed: Unknown host name."; 53 private static final String noremotehost = 54 "Login failed: No remote host header."; 55 private static final String loginfailed = 56 "Login failed for an unknown reason!"; 57 private static final String toomanylogins = 58 "Login failed: You are already logged in! " + 59 "Logout or wait for the session to expire."; 60 private static final String permdenied = 61 "Login failed: Permission denied."; 62 private static final String disabled = 63 "Login failed: Account is disabled."; 64 private static final String nopassword = 65 "Login failed: You must enter a valid password to login."; 66 private static final String badpassword = 67 "Login failed: You must enter a valid password to login."; 68 private static final String badusername = 69 "Login failed: Invalid user name."; 70 71 74 public void run(HttpPresentationComms comms) 75 throws IOException, PageRedirectException,Exception { 76 77 GolfShop application = (GolfShop) comms.application; 78 String fail_url = comms.request.getAppFileURIPath("login/Login.po"); 79 String success_url = comms.request.getAppFileURIPath("main/Main.po"); 80 81 loginState = LoginState.get(comms.session); 82 83 String username = comms.request.getParameter("username"); 89 if (username == null) { 90 myRedirect(fail_url, true, nousername, null, comms); 91 } 92 if (username.length() == 0) { 93 myRedirect(fail_url, true, badusername, null, comms); 94 } 95 String password = comms.request.getParameter("password"); 96 if (password == null) { 97 myRedirect(fail_url, true, nopassword, username, comms); 98 } 99 if (password.length() == 0) { 100 myRedirect(fail_url, true, badpassword, username, comms); 101 } 102 103 try { 104 GolfShopUserManager userManager = application.getUserManager(); 112 113 114 try{ 115 userManager.login(username, password, comms.session); 116 }catch (NullPointerException e){ 117 } 118 myRedirect(success_url, false, null, username, comms); 120 121 } catch (LoginException le) { 122 switch (le.reason) { 123 case GolfShopUserManager.UNKNOWN_ERROR: 124 myRedirect(fail_url, true, loginfailed, username, comms); 125 break; 126 case GolfShopUserManager.IO_ERROR: 127 myRedirect(fail_url, true, badlogin, username, comms); 128 break; 129 case GolfShopUserManager.AUTH_FAILED: 130 myRedirect(fail_url, true, badlogin, username, comms); 131 break; 132 case GolfShopUserManager.MULTIPLE_LOGIN: 133 myRedirect(fail_url, true, toomanylogins, username, comms); 134 break; 135 case GolfShopUserManager.PERMISSION_DENIED: 136 myRedirect(fail_url, true, permdenied, username, comms); 137 break; 138 case GolfShopUserManager.ACCOUNT_DISABLED: 139 myRedirect(fail_url, true, disabled, username, comms); 140 break; 141 default: 142 myRedirect(fail_url, true, loginfailed, username, comms); 143 break; 144 } 145 } 146 } 147 148 152 private void myRedirect(String url, boolean deny, String msg, 153 String username, HttpPresentationComms comms) 154 throws HttpPresentationException { 155 ClientPageRedirectException e = new ClientPageRedirectException(url); 156 if (deny) { 157 loginState.lastError = msg; 158 if ((username != null) && (username.length() > 0)) { 159 loginState.userName = username; 160 } 161 } 162 throw e; 163 } 164 165 } 166 | Popular Tags |