public String doForgotPassword() {
   TypedQuery<User> query = em.createNamedQuery(User.FIND_BY_EMAIL, User.class);
   query.setParameter("email", user.getEmail());
   try {
     user = query.getSingleResult();
     String temporaryPassword = Lorem.getWords(1);
     user.setPassword(PasswordUtils.digestPassword(temporaryPassword));
     em.merge(user);
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_INFO,
             "Email sent",
             "An email has been sent to "
                 + user.getEmail()
                 + " with temporary password :"******"dummyPassword"
     return doLogout();
   } catch (NoResultException e) {
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             "Unknown email",
             "This email address is unknonw in our system"));
     return null;
   }
 }
 public String doUpdateProfile() {
   if (password1 != null && !password1.isEmpty())
     user.setPassword(PasswordUtils.digestPassword(password1));
   em.merge(user);
   resetPasswords();
   facesContext.addMessage(
       null,
       new FacesMessage(
           FacesMessage.SEVERITY_INFO,
           "Profile has been updated for " + user.getFirstName(),
           null));
   return null;
 }
 public String doSignin() {
   TypedQuery<User> query = em.createNamedQuery(User.FIND_BY_LOGIN_PASSWORD, User.class);
   query.setParameter("login", user.getLogin());
   query.setParameter("password", PasswordUtils.digestPassword(user.getPassword()));
   try {
     user = query.getSingleResult();
     // If the user is an administrator
     if (user.getRole().equals(UserRole.ADMIN)) admin = true;
     // If the user has clicked on remember me
     if (rememberMe) {
       String uuid = UUID.randomUUID().toString();
       user.setUuid(uuid);
       addCookie(uuid);
     } else {
       user.setUuid(null);
       removeCookie();
     }
     // The user is now logged in
     loggedIn = true;
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_INFO,
             "Welcome back " + user.getFirstName(),
             "You can now browse the catalog"));
     return "/main";
   } catch (NoResultException e) {
     facesContext.addMessage(
         null,
         new FacesMessage(
             FacesMessage.SEVERITY_WARN,
             "Wrong user/password",
             "Check your inputs or ask for a new password"));
     return null;
   }
 }