Example #1
0
 public String loginUser() {
   User user = userFacade.findByUsername(getUsername());
   if (user == null) {
     errorMessage = "Invalid username or password!";
     return "";
   } else {
     if (user.getUsername().equals(getUsername()) && user.getPassword().equals(getPassword())) {
       errorMessage = "";
       initializeSessionMap(user);
       return "DailyProgress?faces-redirect=true";
     }
     errorMessage = "Invalid username or password!";
     return "";
   }
 }
Example #2
0
 public void initializeSessionMap(User user) {
   FacesContext.getCurrentInstance()
       .getExternalContext()
       .getSessionMap()
       .put("first_name", user.getFirstName());
   FacesContext.getCurrentInstance()
       .getExternalContext()
       .getSessionMap()
       .put("last_name", user.getLastName());
   FacesContext.getCurrentInstance()
       .getExternalContext()
       .getSessionMap()
       .put("username", username);
   FacesContext.getCurrentInstance()
       .getExternalContext()
       .getSessionMap()
       .put("user_id", user.getId());
 }