Search in sources :

Example 1 with ResetPasswordPageModel

use of org.activityinfo.server.login.model.ResetPasswordPageModel in project activityinfo by bedatadriven.

the class ResetPasswordController method resetPassword.

@POST
@Produces(MediaType.TEXT_HTML)
@Transactional
public Viewable resetPassword(@FormParam("email") String email) {
    try {
        User user = userDAO.get().findUserByEmail(email);
        user.setChangePasswordKey(SecureTokenGenerator.generate());
        user.setDateChangePasswordKeyIssued(new Date());
        mailer.send(new ResetPasswordMessage(user));
        ResetPasswordPageModel model = new ResetPasswordPageModel();
        model.setEmailSent(true);
        return model.asViewable();
    } catch (NoResultException e) {
        ResetPasswordPageModel model = new ResetPasswordPageModel();
        model.setLoginError(true);
        return model.asViewable();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Failed to send password reset email", e);
        ResetPasswordPageModel model = new ResetPasswordPageModel();
        model.setEmailError(true);
        return model.asViewable();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) ResetPasswordPageModel(org.activityinfo.server.login.model.ResetPasswordPageModel) NoResultException(javax.persistence.NoResultException) Date(java.util.Date) ServletException(javax.servlet.ServletException) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException) ResetPasswordMessage(org.activityinfo.server.mail.ResetPasswordMessage) Transactional(org.activityinfo.server.database.hibernate.dao.Transactional)

Aggregations

IOException (java.io.IOException)1 Date (java.util.Date)1 NoResultException (javax.persistence.NoResultException)1 ServletException (javax.servlet.ServletException)1 Transactional (org.activityinfo.server.database.hibernate.dao.Transactional)1 User (org.activityinfo.server.database.hibernate.entity.User)1 ResetPasswordPageModel (org.activityinfo.server.login.model.ResetPasswordPageModel)1 ResetPasswordMessage (org.activityinfo.server.mail.ResetPasswordMessage)1