public async Task <IActionResult> ForgotPassword(UserForfotPasswordViewModel model) { if (ModelState.IsValid) { string code = null; try { code = await this.userService.GetUserForgotPasswordCodeAsync(model); } catch (Exception) { TempData[TempDataKeys.TempDataNonExistentEmailKey] = string.Format(ErrorMessages.UserWithEmailDoesNotExist, model.Email); } var callbackUrl = Url.Page( Routes.UserResetPassword, pageHandler: null, values: new { code }, protocol: Request.Scheme); await emailSender.SendEmailAsync( model.Email, StringConstants.ResetPassword, string.Format(SuccessMessages.ForgotPassword, HtmlEncoder.Default.Encode(callbackUrl))); return(Redirect(StringConstants.ForgotPasswordConfirmation)); } return(this.View(model)); }
public async Task <string> GetUserForgotPasswordCodeAsync(UserForfotPasswordViewModel model) { var user = await userManager.FindByEmailAsync(model.Email); if (user == null) { throw new ApplicationException(ErrorMessages.UnableToLoadUser); } var code = await userManager.GeneratePasswordResetTokenAsync(user); return(code); }