1 19 20 package com.lutris.airsent.presentation.customer; 21 22 import com.lutris.appserver.server.httpPresentation.*; 23 import com.lutris.appserver.server.session.*; 24 import com.lutris.util.*; 25 import org.w3c.dom.*; 28 import org.w3c.dom.html.*; 29 import org.enhydra.xml.xmlc.XMLObject; 30 import com.lutris.airsent.spec.AirSentException; 31 import com.lutris.airsent.presentation.BasePO; 32 import com.lutris.airsent.presentation.AirSentPresentationException; 33 import com.lutris.airsent.presentation.AirSentConstants; 34 import com.lutris.airsent.spec.HomeManager; 35 36 37 import com.lutris.airsent.spec.customer.Customer; 38 import com.lutris.airsent.spec.address.*; 39 40 import java.util.*; 41 42 46 public class Register extends BasePO { 47 48 51 private static final int AUTH_LEVEL = AirSentConstants.UNAUTH_USER; 52 String _login = null; 53 String _password = null; 54 String _firstname = null; 55 String _lastname = null; 56 String _repassword = null; 57 String _email = null; 58 String _postal = null; 59 String _street = null; 60 String _phone = null; 61 String _company = null; 62 String _city = null; 63 64 70 public int getRequiredAuthLevel() { 71 return AUTH_LEVEL; 72 } 73 74 77 public XMLObject handleDefault() throws HttpPresentationException { 78 return showPage(null); 79 } 80 81 86 public XMLObject showPage(String errorMsg) 87 throws AirSentPresentationException { 88 RegisterHTML page = (RegisterHTML) myComms.xmlcFactory.create(RegisterHTML.class); 89 try { 90 initCustomer(page); 91 if (null != errorMsg || null != (errorMsg = getSessionData().getAndClearUserMessage())) { 92 page.setTextErrorText(errorMsg); 93 } else { 94 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 95 } 96 populateForm(page); 97 } catch (Exception e) { 98 throw new AirSentPresentationException("System error showing page", e); 99 } 100 return page; 101 } 102 103 107 public XMLObject handleRegister() 108 throws HttpPresentationException { 109 try { 110 getParameters(); 111 Customer user = getSessionData().getCustomer(); 112 boolean virgin = true; 113 if (user != null) { 114 virgin = false; 115 } 116 117 String error = validateForm(user); 118 if (error != null) { 119 return showPage(error); 120 } 121 122 if (_repassword != null && !_repassword.equals(_password)) { 123 return showPage("Please make sure your password and password confirmation match exactly"); 124 } 125 126 HomeManager hf = getApplication().getHomeManager(); 127 if (virgin == true) { 128 user = hf.getCustomerManager().findByLogin(_login); 129 if (user != null) { 130 return showPage("The login name " + _login + " is already in use."); 131 } else { 132 user = hf.getCustomerManager().create(); 133 } 134 } 135 136 if (virgin == true) { 137 user.setLogin(_login); 138 user.setPassword(_password); 139 } 140 user.setFirstName(_firstname); 141 user.setLastName(_lastname); 142 user.setEmail(_email); 143 user.setBusiness(_company); 144 Address address = user.getAddress(); 145 address.setPostalCode(_postal); 146 address.setStreet1(_street); 147 address.setCity(_city); 148 address.setLocalNumber(_phone); 149 user.save(); 150 151 getSessionData().setCustomer(user); 152 getSessionData().setUserAuth(AirSentConstants.CUSTOMER_USER); 153 getSessionData().setUserMessage("Welcome, " + user.getFirstName()); 154 throw new ClientPageRedirectException(AirSentConstants.ORDERSTEP1_PO); 155 161 }catch(NullPointerException e){ 162 return showPage("You cannot register for an Account while running AirSent_pres") ; 163 164 } catch (Exception e) { 165 throw new AirSentPresentationException("Exception logging in user: ", e); 166 } 167 } 168 169 172 protected void initCustomer(RegisterHTML page) 173 throws AirSentPresentationException { 174 175 try { 176 Customer customer = getSessionData().getCustomer(); 177 if(customer != null) { 178 _login = customer.getLogin(); 179 _password = customer.getPassword(); 180 _firstname = customer.getFirstName(); 181 _lastname = customer.getLastName(); 182 _repassword = customer.getPassword(); 183 _email = customer.getEmail(); 184 _company = customer.getBusiness(); 185 _postal = customer.getAddress().getPostalCode(); 186 _street = customer.getAddress().getStreet1(); 187 _phone = customer.getAddress().getLocalNumber(); 188 _city = customer.getAddress().getCity(); 189 } 190 } catch (AirSentException ex) { 191 throw new AirSentPresentationException("Exception initializing customer: ", ex); 192 } 193 } 194 195 199 public void populateForm(RegisterHTML page) { 200 Customer customer = getSessionData().getCustomer(); 201 202 if ((_login != null) && (customer != null)) { 203 page.setTextTitle("My Account"); 205 page.getElementLogin().getParentNode().removeChild(page.getElementLogin()); 206 page.getElementPassword().getParentNode().removeChild(page.getElementPassword()); 207 page.getElementPasswordverify().getParentNode().removeChild(page.getElementPasswordverify()); 208 page.getElementCancelBtn().setHref(AirSentConstants.ORDERSTEP1_PO); 209 page.setTextLoginText(_login); 210 page.setTextPasswordText(_password); 211 page.setTextPasswordverifyText(_password); 212 page.setTextTableHeader("My Account"); 213 } else { 214 215 page.getElementLoginText().getParentNode().removeChild(page.getElementLoginText()); 217 page.getElementLogin().setValue(_login); 218 page.getElementPasswordText().getParentNode().removeChild(page.getElementPasswordText()); 219 page.getElementPassword().setValue(_password); 220 page.getElementPasswordverifyText().getParentNode().removeChild(page.getElementPasswordverifyText()); 221 page.getElementPasswordverify().setValue(_password); 222 223 } 224 225 if(_firstname != null) { 226 page.getElementFirstname().setValue(_firstname); 227 } 228 if(_lastname != null) { 229 page.getElementLastname().setValue(_lastname); 230 } 231 if(_repassword != null) { 232 page.getElementPasswordverify().setValue(_repassword); 233 } 234 if(_email != null) { 235 page.getElementEmail().setValue(_email); 236 } 237 if(_postal != null) { 238 page.getElementPostalcode().setValue(_postal); 239 } 240 if(_street != null) { 241 page.getElementStreet1().setValue(_street); 242 } 243 if(_phone != null) { 244 page.getElementPhone().setValue(_phone); 245 } 246 if(_city != null) { 247 page.getElementCity().setValue(_city); 248 } 249 if(_company != null) { 250 page.getElementCompany().setValue(_company); 251 } 252 253 } 254 255 259 public String validateForm(Customer user) { 260 261 if (user == null) { 262 263 if (isNullField(_login)) { 264 return "Please provide a login"; 265 } 266 267 if (isNullField(_password)) { 268 return "Please provide a password"; 269 } 270 271 if (isNullField(_repassword)) { 272 return "Please provide a password verification"; 273 } 274 275 } 276 277 if (isNullField(_firstname)) { 278 return "Please provide a first name"; 279 } 280 281 if (isNullField(_lastname)) { 282 return "Please provide a last name"; 283 } 284 285 if (isNullField(_email)) { 286 return "Please provide an email"; 287 } 288 289 if (isNullField(_postal)) { 290 return "Please provide a postal code"; 291 } 292 293 if (isNullField(_street)) { 294 return "Please provide a street address"; 295 } 296 297 if (isNullField(_phone)) { 298 return "Please provide a phone number"; 299 } 300 301 if (isNullField(_company)) { 302 return "Please provide a company name"; 303 } 304 305 if (isNullField(_city)) { 306 return "Please provide a city"; 307 } 308 309 return null; 310 } 311 312 315 private void getParameters() 316 throws AirSentPresentationException { 317 318 try { 319 _login = this.getComms().request.getParameter(AirSentConstants.LOGIN_NAME); 320 _password = this.getComms().request.getParameter(AirSentConstants.PASSWORD_NAME); 321 _firstname = this.getComms().request.getParameter(AirSentConstants.FIRST_NAME); 322 _lastname = this.getComms().request.getParameter(AirSentConstants.LAST_NAME); 323 _repassword = this.getComms().request.getParameter(AirSentConstants.PASSWORD_VERIFY_NAME); 324 _email = this.getComms().request.getParameter(AirSentConstants.EMAIL_NAME); 325 _postal = this.getComms().request.getParameter(AirSentConstants.POSTAL_CODE_NAME); 326 _street = this.getComms().request.getParameter(AirSentConstants.STREET1_NAME); 327 _phone = this.getComms().request.getParameter(AirSentConstants.PHONE_NAME); 328 _company = this.getComms().request.getParameter(AirSentConstants.COMPANY_NAME); 329 _city = this.getComms().request.getParameter(AirSentConstants.CITY_NAME); 330 } catch (Exception e) { 331 throw new AirSentPresentationException("ERROR: getting parameters", e); 332 } 333 } 334 } 335 336 337 338 339 | Popular Tags |