1 23 24 package discRack.presentation.personMgmt; 25 26 27 import discRack.presentation.BasePO; 28 import discRack.presentation.DiscRackPresentationException; 29 import discRack.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 42 43 44 45 import org.enhydra.dods.exceptions.AssertionDataObjectException; 46 47 52 public class Register extends BasePO { 53 54 57 private static String LOGINNAME = "login"; 58 private static String PASSWORD = "password"; 59 private static String REPASSWORD = "repassword"; 60 private static String FIRSTNAME = "firstname"; 61 private static String LASTNAME = "lastname"; 62 63 66 public boolean loggedInUserRequired() { 67 return false; 68 } 69 70 76 public XMLObject handleDefault() 77 throws HttpPresentationException { 78 return showPage(null); 79 } 80 81 88 public XMLObject handleRegister() 89 throws HttpPresentationException { 90 91 String login = this.getComms().request.getParameter(LOGINNAME); 92 String password = this.getComms().request.getParameter(PASSWORD); 93 String firstname = this.getComms().request.getParameter(FIRSTNAME);; 94 String lastname = this.getComms().request.getParameter(LASTNAME); 95 String repassword = this.getComms().request.getParameter(REPASSWORD); 96 97 if (login.length() == 0 || password.length() ==0 || 99 firstname.length() == 0 || lastname.length() == 0) { 100 return showPage("Missing information. Please make sure all fields are filled out exactly"); 101 } 102 103 if(!repassword.equals(password)) { 105 return showPage("Please make sure your password and password confirmation match exactly"); 106 } 107 108 109 114 try { 115 116 Person user=((PersonGenerator)PersonGeneratorFactory.getPersonGenerator("discRack.business.person.PersonGeneratorImpl")).findPerson(login); 117 118 if(null == user) 120 { 121 122 user= PersonFactory.getPerson("discRack.business.person.PersonImpl"); 123 124 user.setLogin(login); 125 user.setPassword(password); 126 user.setFirstname(firstname); 127 user.setLastname(lastname); 128 user.save(); 130 131 132 this.getSessionData().setUserMessage("You are registered, " + 133 user.getFirstname() + ", please log in"); 134 throw new ClientPageRedirectException(getComms().request.getApplicationPath()+LOGIN_PAGE); 135 } else { 136 return showPage("The login name " + login + " is already taken. Please try another."); 139 } 140 }catch(NullPointerException ex){ 141 return showPage("You canot register while you in discRack_pres "); 142 143 } 144 catch (AssertionDataObjectException ex) { 145 return showPage("Table person is read-only: can't register another person."); 146 } 147 catch(DiscRackException ex) { 148 throw new DiscRackPresentationException("Exception logging in user: ", ex); 149 } 150 } 151 152 159 public XMLObject showPage(String errorMsg) 160 throws HttpPresentationException { 161 162 RegisterHTML page = (RegisterHTML)myComms.xmlcFactory.create(RegisterHTML.class); 163 164 if(null == errorMsg) { 165 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 166 } else { 167 page.setTextErrorText(errorMsg); 168 } 169 170 if(null != this.getComms().request.getParameter(LOGINNAME)) { 171 page.getElementLogin().setValue(this.getComms().request.getParameter(LOGINNAME)); 172 } 173 if(null != this.getComms().request.getParameter(FIRSTNAME)) { 174 page.getElementFirstname().setValue(this.getComms().request.getParameter(FIRSTNAME)); 175 } 176 if(null != this.getComms().request.getParameter(LASTNAME)) { 177 page.getElementLastname().setValue(this.getComms().request.getParameter(LASTNAME)); 178 } 179 180 return page; 181 } 182 } 183 | Popular Tags |