/** * Sends the current log in object to the EJB * * @return Will either return the user to the log in page (if creation was successful) OR will * return user back to the register page with an error message * @throws NoSuchAlgorithmException This error is thrown if the password encryption fails */ public String createUser() throws NoSuchAlgorithmException { if (!detentionTrackerBean.userExists(currentLogin.getUsername())) { // If new username does not already exists... detentionTrackerBean.createInitialLogin(currentLogin); return "login?faces-redirect=true"; } // else if it does already exists... displayMessage( "Username already exists OR you have entered incorrect characters (letters & numbers only!)"); return null; }
/** * Will log the user into the web site using container managed security * * @return Will take the user to the Welcome page or will return the user back to the log in page * with an error message */ public String login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { // If the log in is successful.. request.login(currentLogin.getUsername(), currentLogin.getPassword()); return "welcome?faces-redirect=true"; } catch (ServletException e) { // else... displayMessage("Username or password is incorrect!"); return null; } }