1 20 21 package golfShop.presentation.xmlc.login; 22 23 import java.io.*; 24 import java.net.*; 25 import com.lutris.util.*; 26 import com.lutris.http.*; 27 import golfShop.GolfShop; 28 import com.lutris.appserver.server.httpPresentation.*; 29 import com.lutris.appserver.server.user.*; 30 import golfShop.spec.user.*; 31 import golfShop.spec.LoginException; 32 40 public class AccountProcessor implements HttpPresentation { 41 44 private LoginState loginState; 45 46 private static final String nousername = 47 "You must enter a username for the new account."; 48 private static final String nopassword = 49 "You must enter the new password twice."; 50 private static final String badpassword = 51 "Error entering password! Enter the new password twice."; 52 private static final String badlogin = 53 "Incorrect username or password."; 54 private static final String unknownhost = 55 "Login failed: Unknown host name."; 56 private static final String noremotehost = 57 "Login failed: No remote host header."; 58 private static final String loginfailed = 59 "Account creation failed: Unknown reason!"; 60 private static final String userexists = 61 "Account creation failed: Username is already in use."; 62 private static final String badusername = 63 "That is not a valid user name."; 64 private static final String toomanylogins = 65 "Account creation failed: Exceeded maximum number of sessions."; 66 private static final String permdenied = 67 "Login failed: Permission denied."; 68 private static final String disabled = 69 "Login failed: Account is disabled."; 70 71 72 75 private String fixStr(String str) { 76 if (str == null) { 77 str = ""; 78 } 79 return str; 80 } 81 82 83 86 public void run(HttpPresentationComms comms) 87 throws IOException, PageRedirectException, Exception { 88 loginState = LoginState.get(comms.session); 89 90 GolfShop application = (GolfShop) comms.application; 91 String fail_url = comms.request.getAppFileURIPath("login/NewAccount.po"); 92 String success_url = comms.request.getAppFileURIPath("main/Main.po"); 93 InetAddress[] inet = new InetAddress[1]; 94 95 String username = comms.request.getParameter("username"); 99 if (username == null) { 100 myRedirect(fail_url, true, nousername, null, comms); 101 } 102 if (username.length() == 0) { 103 myRedirect(fail_url, true, badusername, null, comms); 104 } 105 String password = comms.request.getParameter("password"); 106 String password2 = comms.request.getParameter("password2"); 107 if ((password == null) || (password2 == null)) { 108 myRedirect(fail_url, true, nopassword, username, comms); 109 } 110 if (!password.equals(password2)) { 111 myRedirect(fail_url, true, badpassword, username, comms); 112 } 113 if (password.length() == 0) { 114 myRedirect(fail_url, true, badpassword, username, comms); 115 } 116 117 String address1 = fixStr(comms.request.getParameter("address1")); 122 if (address1 == null) { 123 address1 = ""; 124 } 125 String address2 = fixStr(comms.request.getParameter("address2")); 126 if (address2 == null) { 127 address2 = ""; 128 } 129 String city = fixStr(comms.request.getParameter("city")); 130 String state = fixStr(comms.request.getParameter("state")); 131 String zip = fixStr(comms.request.getParameter("zip")); 132 String creditCard = fixStr(comms.request.getParameter("creditCard")); 133 String email = fixStr(comms.request.getParameter("email")); 134 135 String remoteHost = comms.request.getRemoteHost(); 140 if (remoteHost == null) { 142 myRedirect(fail_url, true, noremotehost, username, comms); 143 } 144 inet[0] = null; 145 try { 146 inet[0] = InetAddress.getByName(remoteHost); 147 } catch (UnknownHostException uh) { 148 } 150 if (inet[0] == null) { 151 myRedirect(fail_url, true, unknownhost, username, comms); 152 } 153 154 try { 155 GolfShopUserManager userManager = application.getUserManager(); 165 userManager.createAccount(username, password, address1, 166 address2, city, state, zip, creditCard, 167 email, comms.session); 168 myRedirect(success_url, false, null, username, comms); 170 176 177 } catch(NullPointerException ex) { 178 179 myRedirect(fail_url, true, "You cannot register user while runing GolfShop_pres", username, comms); 180 }catch (LoginException le) { 181 switch (le.reason) { 182 case GolfShopUserManager.UNKNOWN_ERROR: 183 myRedirect(fail_url, true, loginfailed, username, comms); 184 break; 185 case GolfShopUserManager.IO_ERROR: 186 myRedirect(fail_url, true, badlogin, username, comms); 187 break; 188 case GolfShopUserManager.AUTH_FAILED: 189 myRedirect(fail_url, true, badlogin, username, comms); 190 break; 191 case GolfShopUserManager.MULTIPLE_LOGIN: 192 myRedirect(fail_url, true, toomanylogins, username, comms); 193 break; 194 case GolfShopUserManager.PERMISSION_DENIED: 195 myRedirect(fail_url, true, permdenied, username, comms); 196 break; 197 case GolfShopUserManager.ACCOUNT_DISABLED: 198 myRedirect(fail_url, true, disabled, username, comms); 199 break; 200 case GolfShopUserManager.USERNAME_ALREADY_EXISTS: 201 myRedirect(fail_url, true, userexists, username, comms); 202 break; 203 default: 204 myRedirect(fail_url, true, loginfailed, username, comms); 205 break; 206 } 207 } 208 } 209 210 214 private void myRedirect(String url, boolean deny, String msg, 215 String username, HttpPresentationComms comms) 216 throws HttpPresentationException { 217 218 ClientPageRedirectException e = new ClientPageRedirectException(url); 219 if (deny) { 220 loginState.lastError = msg; 221 if ((username != null) && (username.length() > 0)) { 222 loginState.userName = username; 223 } 224 } 225 throw e; 226 } 227 } 228 | Popular Tags |