Exemplo n.º 1
0
  private Account checkRecoveryForm(
      NativeWebRequest request, RecoveryConfirmationForm form, BindingResult result) {
    if (isEmpty(form.getEmail())) {
      result.rejectValue("email", "account.register.email.err.blank");
    }

    if (isEmpty(form.getPassword())) {
      result.rejectValue("password", "account.register.pwd.err.blank");
    }

    if (isEmpty(form.getToken())) {
      result.rejectValue(
          "token", "account.recovery.err.token", new Object[] {form.getEmail()}, null);
    }

    if (isEmpty(form.getConfirm())) {
      result.rejectValue("confirm", "account.register.pwd-cfr.err.blank");
    } else if (!form.getPassword().equals(form.getConfirm())) {
      result.rejectValue("confirm", "account.register.pwd-cfr.err.mismatch");
    }

    if (captchaService != null) {
      captchaService.validateCaptcha(request, result);
    }

    Account player = null;
    try {
      player = accountManager.findByEmail(form.getEmail());
      if (player != null) {
        final RecoveryToken token = recoveryTokenManager.getToken(player);
        if (token == null) {
          result.rejectValue(
              "token", "account.recovery.err.expired", new Object[] {form.getEmail()}, null);
        } else if (!token.getToken().equals(form.getToken())) {
          result.rejectValue(
              "token", "account.recovery.err.token", new Object[] {form.getEmail()}, null);
        }
      } else {
        result.rejectValue("email", "account.recovery.err.unknown");
      }
    } catch (Exception ex) {
      result.rejectValue("token", "account.recovery.err.system");
    }
    return player;
  }
Exemplo n.º 2
0
  @RequestMapping(value = "request")
  @Transactional(propagation = Propagation.REQUIRES_NEW)
  public String recoveryRequestPage(
      HttpSession session,
      Model model,
      @Valid @ModelAttribute("recovery") RecoveryRequestForm form,
      BindingResult result) {
    log.info("Recovery password for {}", form);

    if (form.isRecoveryAccount()) {
      try {
        final Account account = accountManager.findByEmail(form.getEmail());
        if (account != null) {
          final RecoveryToken token = recoveryTokenManager.generateToken(account);
          log.info("Recovery token generated: {}", token);

          final Map<String, Object> mailModel = new HashMap<>();
          mailModel.put("principal", account);
          mailModel.put("recoveryToken", token.getToken());

          final Member member = personalityManager.getMember(account.getId());
          notificationService.raiseNotification(
              "account.recovery", member, NotificationSender.ACCOUNTS, mailModel);
          session.setAttribute(RECOVERING_PLAYER_EMAIL, account.getEmail());
          return "redirect:/account/recovery/confirmation";
        } else {
          result.rejectValue("email", "account.recovery.err.unknown");
        }
      } catch (Exception ex) {
        log.error("Recovery password email can't be delivered", ex);
        result.rejectValue("email", "account.recovery.err.system");
      }
    }
    model.addAttribute("resourceTemplate", "/content/account/recovery/request.ftl");
    return "/content/assistance/help";
  }