Ejemplo n.º 1
0
 /**
  * Verify.
  *
  * @param token the token
  * @return the result
  */
 public static Result verify(final String token) {
   Logger.debug("Account verify");
   com.feth.play.module.pa.controllers.Authenticate.noCache(response());
   final TokenAction ta = tokenIsValid(token, Type.EMAIL_VERIFICATION);
   if (ta == null) {
     return badRequest(no_token_or_invalid.render());
   }
   final String email = ta.targetUser.email;
   //		final User verifiedUser = ta.targetUser;
   // if(session().containsKey("acctType") && StringUtils.equals("event",
   // session().get("acctType"))) {
   // verifiedUser.addRoles(SecurityRole.EVENT_ADMIN);
   // } else {
   // verifiedUser.addRoles(SecurityRole.PFP_ADMIN);
   // }
   User.verify(ta.targetUser);
   flash(
       ControllerUtil.FLASH_INFO_KEY,
       Messages.get("playauthenticate.verify_email.success", email));
   if (ControllerUtil.getLocalUser(session()) != null) {
     return redirect(routes.Application.index());
   } else {
     return redirect(routes.Signup.login());
   }
 }
  /**
   * Change password.
   *
   * @return the result
   */
  @SubjectPresent
  public static Result changePassword() {
    com.feth.play.module.pa.controllers.Authenticate.noCache(response());
    final User u = ControllerUtil.getLocalUser(session());

    if (!u.emailValidated) {
      return ok(unverified.render());
    } else {
      return ok(password_change.render(PASSWORD_CHANGE_FORM));
    }
  }
 /**
  * Do change password.
  *
  * @return the result
  */
 @SubjectPresent
 public static Result doChangePassword() {
   com.feth.play.module.pa.controllers.Authenticate.noCache(response());
   final Form<Account.PasswordChange> filledForm = PASSWORD_CHANGE_FORM.bindFromRequest();
   if (filledForm.hasErrors()) {
     // User did not select whether to link or not link
     return badRequest(password_change.render(filledForm));
   } else {
     final User user = ControllerUtil.getLocalUser(session());
     final String newPassword = filledForm.get().password;
     user.changePassword(new EmailAuthUser(newPassword), true);
     flash(
         ControllerUtil.FLASH_INFO_KEY, Messages.get("playauthenticate.change_password.success"));
     return redirect(routes.Application.profile());
   }
 }
 /**
  * Verify email.
  *
  * @return the result
  */
 @SubjectPresent
 public static Result verifyEmail() {
   com.feth.play.module.pa.controllers.Authenticate.noCache(response());
   final User user = ControllerUtil.getLocalUser(session());
   if (user.emailValidated) {
     // E-Mail has been validated already
     flash(
         ControllerUtil.FLASH_INFO_KEY,
         Messages.get("playauthenticate.verify_email.error.already_validated"));
   } else if ((user.email != null) && !user.email.trim().isEmpty()) {
     flash(
         ControllerUtil.FLASH_INFO_KEY,
         Messages.get("playauthenticate.verify_email.message.instructions_sent", user.email));
     EmailAuthProvider.getProvider().sendVerifyEmailMailingAfterSignup(user, ctx());
   } else {
     flash(
         ControllerUtil.FLASH_INFO_KEY,
         Messages.get("playauthenticate.verify_email.error.set_email_first", user.email));
   }
   return redirect(routes.Application.profile());
 }