Search in sources :

Example 1 with InvalidInvitePageModel

use of org.activityinfo.server.login.model.InvalidInvitePageModel 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)

Example 2 with InvalidInvitePageModel

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

the class ConfirmInviteController method confirm.

@POST
public Response confirm(@Context UriInfo uri, @FormParam("key") String key, @FormParam("locale") String locale, @FormParam("password") String password, @FormParam("name") String name, @FormParam("newsletter") boolean newsletter) throws Exception {
    User user = null;
    try {
        user = userDAO.get().findUserByChangePasswordKey(key);
        user.setName(checkNonEmpty(name));
        user.setLocale(checkNonEmpty(locale));
        user.changePassword(checkNonEmpty(password));
        user.clearChangePasswordKey();
        user.setEmailNotification(true);
        mailingList.subscribe(user, true, newsletter);
        return Response.seeOther(uri.getAbsolutePathBuilder().replacePath("/app").build()).cookie(authTokenProvider.createNewAuthCookies(user)).build();
    } catch (EntityNotFoundException e) {
        return Response.ok(new InvalidInvitePageModel().asViewable()).type(MediaType.TEXT_HTML).build();
    } catch (IllegalArgumentException e) {
        return Response.ok(ConfirmInvitePageModel.incompleteForm(user).asViewable()).type(MediaType.TEXT_HTML).build();
    }
}
Also used : User(org.activityinfo.server.database.hibernate.entity.User) EntityNotFoundException(javax.persistence.EntityNotFoundException) InvalidInvitePageModel(org.activityinfo.server.login.model.InvalidInvitePageModel)

Aggregations

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