Example #1
0
  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;
  }
Example #2
0
 public void forgotPassword() {
   try {
     IUser foundUser = loginEjb.findByuseranswer(user, passwordQ);
     loginMessage = "Your Password is " + foundUser.getPassword();
   } catch (NoResultException ex) {
     loginMessage = "No such user";
   }
   //        if (passwordQ.equals(user.getSecuritAnswer())) {
   //            loginMessage = user.getPassword();
   //        } else {
   //            loginMessage = "No such user";
   //        }
 }