Search in sources :

Example 1 with ChangePasswordPageModel

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

the class ChangePasswordController method changePassword.

@POST
public Response changePassword(@Context UriInfo uri, @FormParam("key") String key, @FormParam("password") String password, @FormParam("password2") String password2) throws IOException, ServletException {
    User user = null;
    try {
        user = userDAO.get().findUserByChangePasswordKey(key);
    } catch (NoResultException e) {
        return ok(new InvalidInvitePageModel());
    }
    if (password == null || password.length() < MINIMUM_PASSWORD_LENGTH) {
        return ok(new ChangePasswordPageModel(user).setPasswordLengthInvalid(true));
    }
    if (!password.equals(password2)) {
        return ok(new ChangePasswordPageModel(user).setPasswordsNotMatched(true));
    }
    changePassword(user, password);
    return Response.seeOther(uri.getAbsolutePathBuilder().replacePath("/").build()).cookie(authTokenProvider.createNewAuthCookies(user)).build();
}
Also used : ChangePasswordPageModel(org.activityinfo.server.login.model.ChangePasswordPageModel) User(org.activityinfo.server.database.hibernate.entity.User) NoResultException(javax.persistence.NoResultException) InvalidInvitePageModel(org.activityinfo.server.login.model.InvalidInvitePageModel)

Aggregations

NoResultException (javax.persistence.NoResultException)1 User (org.activityinfo.server.database.hibernate.entity.User)1 ChangePasswordPageModel (org.activityinfo.server.login.model.ChangePasswordPageModel)1 InvalidInvitePageModel (org.activityinfo.server.login.model.InvalidInvitePageModel)1