1 23 24 package barracudaDiscRack.presentation.personMgmt; 25 26 import barracudaDiscRack.business.person.*; 27 import barracudaDiscRack.presentation.BasePO; 28 import com.lutris.appserver.server.httpPresentation.*; 29 import com.lutris.appserver.server.session.*; 30 import com.lutris.util.*; 31 import org.enhydra.xml.xmlc.*; 32 import org.enhydra.xml.xmlc.html.*; 33 import org.w3c.dom.*; 34 import org.w3c.dom.html.*; 35 import org.enhydra.xml.xmlc.XMLObject; 36 import barracudaDiscRack.presentation.DiscRackPresentationException; 37 import barracudaDiscRack.business.DiscRackBusinessException; 38 39 46 public class Register extends BasePO { 47 48 51 private static String LOGINNAME = "login"; 52 private static String PASSWORD = "password"; 53 private static String REPASSWORD = "repassword"; 54 private static String FIRSTNAME = "firstname"; 55 private static String LASTNAME = "lastname"; 56 57 60 public boolean loggedInUserRequired() { 61 return false; 62 } 63 64 70 public XMLObject handleDefault() 71 throws HttpPresentationException { 72 return showPage(null); 73 } 74 75 82 public XMLObject handleRegister() 83 throws HttpPresentationException { 84 85 String login = this.getComms().request.getParameter(LOGINNAME); 86 String password = this.getComms().request.getParameter(PASSWORD); 87 String firstname = this.getComms().request.getParameter(FIRSTNAME);; 88 String lastname = this.getComms().request.getParameter(LASTNAME); 89 String repassword = this.getComms().request.getParameter(REPASSWORD); 90 91 if (login.length() == 0 || password.length() ==0 || 93 firstname.length() == 0 || lastname.length() == 0) { 94 return showPage("Missing information. Please make sure all fields are filled out exactly"); 95 } 96 97 if(!repassword.equals(password)) { 99 return showPage("Please make sure your password and password confirmation match exactly"); 100 } 101 102 try { 103 if(null == PersonFactory.findPerson(login)) { 105 Person user = new Person(); 106 user.setLogin(login); 107 user.setPassword(password); 108 user.setFirstname(firstname); 109 user.setLastname(lastname); 110 user.save(); 112 this.getSessionData().setUserMessage("You are registered, " + 113 user.getFirstname() + ", please log in"); 114 throw new ClientPageRedirectException(getComms().request.getApplicationPath() + LOGIN_PAGE); 115 } else { 116 return showPage("The login name " + login + " is already taken. Please try another."); 119 } 120 } catch(DiscRackBusinessException ex) { 121 throw new DiscRackPresentationException("Exception logging in user: ", ex); 122 } 123 } 124 125 132 public XMLObject showPage(String errorMsg) 133 throws HttpPresentationException { 134 135 RegisterHTML page = (RegisterHTML)myComms.xmlcFactory.create(RegisterHTML.class); 136 137 if(null == errorMsg) { 138 page.getElementErrorText().getParentNode().removeChild(page.getElementErrorText()); 139 } else { 140 page.setTextErrorText(errorMsg); 141 } 142 143 if(null != this.getComms().request.getParameter(LOGINNAME)) { 144 page.getElementLogin().setValue(this.getComms().request.getParameter(LOGINNAME)); 145 } 146 if(null != this.getComms().request.getParameter(FIRSTNAME)) { 147 page.getElementFirstname().setValue(this.getComms().request.getParameter(FIRSTNAME)); 148 } 149 if(null != this.getComms().request.getParameter(LASTNAME)) { 150 page.getElementLastname().setValue(this.getComms().request.getParameter(LASTNAME)); 151 } 152 153 return page; 154 } 155 } 156 | Popular Tags |