public String doSignup() {
    // Does the login already exists ?
    if (em.createNamedQuery(User.FIND_BY_LOGIN, User.class)
            .setParameter("login", user.getLogin())
            .getResultList()
            .size()
        > 0) {
      facesContext.addMessage(
          null,
          new FacesMessage(
              FacesMessage.SEVERITY_WARN,
              "Login already exists " + user.getLogin(),
              "You must choose a different login"));
      return null;
    }

    // Everything is ok, we can create the user
    user.setPassword(password1);
    em.persist(user);
    resetPasswords();
    facesContext.addMessage(
        null,
        new FacesMessage(
            FacesMessage.SEVERITY_INFO, "Hi " + user.getFirstName(), "Welcome to this website"));
    loggedIn = true;
    if (user.getRole().equals(UserRole.ADMIN)) admin = true;
    return "/main";
  }
 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;
 }