public String login() { String page = null; try { loginEjb.login(user); System.out.println("login succeed"); System.out.println(session.getPage()); page = session.getPage(); user = userService.find(user.getUsername(), user.getPassword()); session.setUser(user); // authorization // String message = ""; // HttpServletRequest request = (HttpServletRequest) // FacesContext.getCurrentInstance().getExternalContext().getRequest(); // request.getSession().invalidate(); // try { // // //Login via the Servlet Context // request.login(user.getUsername(), user.getPassword()); // // //Retrieve the Principal // Principal principal = request.getUserPrincipal(); // // //Display a message based on the User role // if (request.isUserInRole("Administrator")) { // message = "Username : "******" You are an // Administrator"; // } else if (request.isUserInRole("Faculty")) { // message = "Username : "******" You are only a // Faculty"; // } else if (request.isUserInRole("Staff")) { // message = "Username : "******" You're Staff"; // } else if (request.isUserInRole("Student")) { // message = "Username : "******" You're Student"; // } // // //Add the welcome message to the faces context // FacesContext.getCurrentInstance().addMessage(null, new // FacesMessage(FacesMessage.SEVERITY_INFO, message, null)); // return "success"; // } catch (ServletException e) { // FacesContext.getCurrentInstance().addMessage(null, new // FacesMessage(FacesMessage.SEVERITY_ERROR, "An Error Occured: Login failed", null)); // e.printStackTrace(); // } // return "failure"; // end of authorization // page="adminpage"; } catch (LoginFailException ex) { // page = session.getPage(); loginMessage = "No such user"; } return page; }
public String check() { String page = null; try { // this.user = userService.getUser(id); // IUser foundUser = loginEjb.findByuseranswer(user, passwordQ); // loginEjb.validation(user.getUsername(),user.getSecurityCode()); System.out.println("user.getUsername() = " + user.getUsername()); user = session.getUser(); userService.findByUserCode(user.getUsername(), code); System.out.println("login succeed"); System.out.println(session.getPage()); if (user.getFirstname() == null || user.getLastname() == null || user.getAddress() == null) { session.setUser(user); return "completeregisterforuser"; } for (Role role : user.getRoles()) { if (role.getName().equals("Admin")) { return "listusers"; } else if (role.getName().equals("Staff")) { return "searchstdbyid"; } if (role.getName().equals("Faculty")) { return "facultydashboard"; } if (role.getName().equals("Student")) { return "studentdashboard"; } } } catch (Exception ex) { loginMessage = "The security code is wrong"; } // catch (LoginFailException ex) { // loginMessage = "The security code is wrong"; // } return page; }