1 20 21 package golfShop.data.user; 22 23 import java.io.Serializable ; 24 import com.lutris.util.ConfigException; 25 import com.lutris.appserver.server.*; 26 import golfShop.data.user.*; 27 import golfShop.spec.user.UserDO; 28 import com.lutris.appserver.server.user.*; 29 import golfShop.spec.LoginException; 30 49 public class UserDOImpl implements UserDO,User, Serializable { 50 51 public static final int AUTH_OK = 0; 52 public static final int AUTH_FAILED = 1; 53 54 protected boolean isDirty = false; 55 protected String username = null; 56 private String password = null; 57 protected String address1 = null; 58 protected String address2 = null; 59 protected String city = null; 60 protected String state = null; 61 protected String zip = null; 62 protected String creditCard = null; 63 protected String email= null; 64 65 private static UserStore storage = null; 66 67 70 public static void InitializeStorageOption(String opt,String fn) throws ApplicationException{ 71 72 73 try { 74 Class c = null; 75 if (opt.equalsIgnoreCase("memory")){ 76 c = Class.forName("golfShop.data.user.MemoryUserStore"); 77 storage = (UserStore) c.newInstance(); 78 storage.initializeUserStore(); 79 } 80 else if (opt.equalsIgnoreCase("file")) 81 { 82 c = Class.forName("golfShop.data.user.FileUserStore"); 83 storage = (UserStore) c.newInstance(); 84 storage.initializeUserStore(fn); 85 } 86 else if (opt.equalsIgnoreCase("ldap")) 87 { 88 c = Class.forName("golfShop.data.user.LdapUserStore"); 89 } 90 else 91 throw new ApplicationException("Invalid user store option " + 92 opt); 93 94 95 } catch (ClassNotFoundException cnfe) { 96 throw new ApplicationException("Unable to create user store" + 97 " of type: " + opt + "\n" + cnfe); 98 } catch (IllegalAccessException iae) { 99 throw new ApplicationException("Unable to create user store" + 100 " of type: " + opt + "\n" + iae); 101 } catch (InstantiationException ie) { 102 throw new ApplicationException("Unable to create user store" + 103 " of type: " + opt + "\n" + ie); 104 } 105 106 } 107 108 118 protected UserDOImpl(String username, String password, String address1, 119 String address2, String city, String state, 120 String zip, String creditCard, String email) { 121 this.username = username; 122 this.password = password; 123 this.address1 = address1; 124 this.address2 = address2; 125 this.city = city; 126 this.state = state; 127 this.zip = zip; 128 this.creditCard = creditCard; 129 this.email = email; 130 this.isDirty = false; 131 } 132 133 134 public static UserDO lookupUser(String username) { 135 return storage.lookupUserFromUserStore(username); 136 } 137 138 139 142 public static UserDO createUser(String username, String password, 143 String address1, String address2, String city, 144 String state, String zip, String creditCard, 145 String email) { 146 if (storage.usernameInUserStore(username)) 148 return null; 149 150 UserDOImpl newGuy = new UserDOImpl (username, password, address1, address2, 152 city, state, zip, creditCard, email); 153 storage.addUserToUserStore(newGuy); 155 156 return newGuy; 158 } 159 160 161 170 public void changePassword(String old, String new1, String new2, 171 User initiatingUser) throws LoginException { 172 if ((new1 != new2) || (authenticate(old) != AUTH_OK)) 173 throw new LoginException(AUTH_FAILED); 174 password = new1; 175 isDirty = true; 176 } 177 178 180 public String getName() { 181 return username; 182 } 183 184 185 192 public int authenticate(String password) { 193 if (this.password.equals(password)) 194 return AUTH_OK; 195 else 196 return AUTH_FAILED; 197 } 198 199 protected String getPassword() { 200 return this.password; 201 } 202 203 204 208 public void commitChanges() { 209 if (!isDirty) 210 return; 211 storage.updateUserInUserStore(this); 212 isDirty = false; 213 } 214 215 216 public String getAddress1() { 217 return address1; 218 } 219 220 public void setAddress1(String address1) { 221 if (address1.compareTo(this.address1) != 0) { 222 this.address1 = address1; 223 isDirty = true; 224 } 225 } 226 227 public String getAddress2() { 228 return address2; 229 } 230 231 public void setAddress2(String address2) { 232 if (address2.compareTo(this.address2) != 0) { 233 this.address2 = address2; 234 isDirty = true; 235 } 236 } 237 238 public String getCity() { 239 return city; 240 } 241 242 public void setCity(String city) { 243 if (city.compareTo(this.city) != 0) { 244 this.city = city; 245 isDirty = true; 246 } 247 } 248 249 public String getState() { 250 return state; 251 } 252 253 public void setState(String state) { 254 if (state.compareTo(this.state) != 0) { 255 this.state = state; 256 isDirty = true; 257 } 258 } 259 260 public String getZip() { 261 return zip; 262 } 263 264 public void setZip(String zip) { 265 if (zip.compareTo(this.zip) != 0) { 266 this.zip = zip; 267 isDirty = true; 268 } 269 } 270 271 public String getCreditCard() { 272 return creditCard; 273 } 274 275 public void setCreditCard(String creditCard) { 276 if (creditCard.compareTo(this.creditCard) != 0) { 277 this.creditCard = creditCard; 278 isDirty = true; 279 } 280 } 281 282 public String getEmail() { 283 return email; 284 } 285 286 public void setEmail(String email) { 287 if (email.compareTo(this.email) != 0) { 288 this.email = email; 289 isDirty = true; 290 } 291 } 292 293 297 public boolean equals(Object obj) { 298 return (obj instanceof UserDO) 299 && (((UserDO)obj).getName().equals(getName())); 300 } 301 302 305 public String toString() { 306 return "isDirty = \"" + isDirty + "\", " 307 + "username = \"" + username + "\", " 308 + "password = \"" + password + "\", " 309 + "address1 = \"" + address1 + "\", " 310 + "address2 = \"" + address2 + "\", " 311 + "city = \"" + city + "\", " 312 + "state = \"" + state + "\", " 313 + "zip = \"" + zip + "\", " 314 + "creditCard = \"" + creditCard + "\", " 315 + "email = \"" + email + "\", "; 316 } 317 } 318 319 | Popular Tags |