1 23 24 package transactionsDiscRack.presentation.personMgmt; 25 26 27 import transactionsDiscRack.presentation.BasePO; 28 import transactionsDiscRack.presentation.TransactionsDiscRackPresentationException; 29 import transactionsDiscRack.spec.*; 30 31 import com.lutris.appserver.server.httpPresentation.*; 32 import com.lutris.appserver.server.session.*; 33 import com.lutris.util.*; 34 import org.w3c.dom.*; 37 import org.w3c.dom.html.*; 38 import org.enhydra.xml.xmlc.XMLObject; 39 40 41 import org.enhydra.dods.exceptions.AssertionDataObjectException; 42 43 48 public class Register extends BasePO { 49 50 53 private static String LOGINNAME = "login"; 54 private static String PASSWORD = "password"; 55 private static String REPASSWORD = "repassword"; 56 private static String FIRSTNAME = "firstname"; 57 private static String LASTNAME = "lastname"; 58 59 62 public boolean loggedInUserRequired() { 63 return false; 64 } 65 66 72 public XMLObject handleDefault() 73 throws HttpPresentationException { 74 return showPage(null); 75 } 76 77 84 public XMLObject handleRegister() 85 throws HttpPresentationException { 86 87 String login = this.getComms().request.getParameter(LOGINNAME); 88 String password = this.getComms().request.getParameter(PASSWORD); 89 String firstname = this.getComms().request.getParameter(FIRSTNAME);; 90 String lastname = this.getComms().request.getParameter(LASTNAME); 91 String repassword = this.getComms().request.getParameter(REPASSWORD); 92 93 if (login.length() == 0 || password.length() ==0 || 95 firstname.length() == 0 || lastname.length() == 0) { 96 return showPage("Missing information. Please make sure all fields are filled out exactly"); 97 } 98 99 if(!repassword.equals(password)) { 101 return showPage("Please make sure your password and password confirmation match exactly"); 102 } 103 104 105 110 try { 111 112 Person user=((PersonGenerator)PersonGeneratorFactory.getPersonGenerator("transactionsDiscRack.business.person.PersonGeneratorImpl")).findPerson(login); 113 114 if(null == user) 116 { 117 118 user= PersonFactory.getPerson("transactionsDiscRack.business.person.PersonImpl"); 119 120 user.setLogin(login); 121 user.setPassword(password); 122 user.setFirstname(firstname); 123 user.setLastname(lastname); 124 user.save(); 126 127 128 this.getSessionData().setUserMessage("You are registered, " + 129 user.getFirstname() + ", please log in"); 130 user.dbtRelease(); 131 throw new ClientPageRedirectException(getComms().request.getApplicationPath()+LOGIN_PAGE); 132 } else { 133 return showPage("The login name " + login + " is already taken. Please try another."); 136 } 137 }catch(NullPointerException ex){ 138 return showPage("You canot register while you in TransactionsDiscRack_pres "); 139 } 140 catch (AssertionDataObjectException ex) { 141 return showPage("Table person is read-only: can't register another person."); 142 } 143 catch(TransactionsDiscRackException ex) { 144 throw new TransactionsDiscRackPresentationException("Exception logging in user: ", ex); 145 } 146 } 147 148 155 public XMLObject showPage(String errorMsg) 156 throws HttpPresentationException { 157 158 RegisterHTML page = (RegisterHTML)myComms.xmlcFactory.create(RegisterHTML.class); 159 160 if(null == errorMsg) { 161 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 162 } else { 163 page.setTextErrorText(errorMsg); 164 } 165 166 if(null != this.getComms().request.getParameter(LOGINNAME)) { 167 page.getElementLogin().setValue(this.getComms().request.getParameter(LOGINNAME)); 168 } 169 if(null != this.getComms().request.getParameter(FIRSTNAME)) { 170 page.getElementFirstname().setValue(this.getComms().request.getParameter(FIRSTNAME)); 171 } 172 if(null != this.getComms().request.getParameter(LASTNAME)) { 173 page.getElementLastname().setValue(this.getComms().request.getParameter(LASTNAME)); 174 } 175 176 return page; 177 } 178 } 179 | Popular Tags |