@RequestMapping(value = "confirmation") @Transactional(propagation = Propagation.REQUIRES_NEW) public String recoveredConfirmationAction( NativeWebRequest request, HttpSession session, @Valid @ModelAttribute("recovery") RecoveryConfirmationForm form, BindingResult result, Model model) { log.info("Process recovery confirmation: {}", form); boolean notificationWasSent = false; String email = form.getEmail(); if (isEmpty(email)) { email = (String) session.getAttribute(RECOVERING_PLAYER_EMAIL); notificationWasSent = (email != null && !email.isEmpty()); form.setEmail(email); } session.removeAttribute(RECOVERING_PLAYER_EMAIL); if (isEmpty(email)) { return "redirect:/account/recovery/request"; } if (form.isRecoveryAccount()) { final Account account = checkRecoveryForm(request, form, result); if (!result.hasErrors()) { final AccountEditor e = new AccountEditor(account); try { recoveryTokenManager.clearToken( account); // remove token. Mandatory operation or expired exception will be thrown final Account account1 = accountManager.updateAccount(e.createAccount(), form.getPassword()); final Member member = personalityManager.getMember(account.getId()); notificationService.raiseNotification( "account.updated", member, NotificationSender.ACCOUNTS, member); return AccountController.forwardToAuthorization( request, account1, form.isRememberMe(), null); } catch (Exception e1) { result.rejectValue("email", "account.recovery.err.system"); } } } model.addAttribute("submittedEmail", email); model.addAttribute("notificationWasSent", notificationWasSent); model.addAttribute("resourceTemplate", "/content/account/recovery/confirmation.ftl"); return "/content/assistance/help"; }
@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"; }