public async Task <IActionResult> ForgotPassword([FromBody] UserForForgotPasswordDto userForForgotPasswordDto) { if (userForForgotPasswordDto == null) { return(Ok()); } var user = await _userManager.FindByEmailAsync(userForForgotPasswordDto.Email); if (user == null) { return(Ok()); } //https://stackoverflow.com/questions/6855624/plus-sign-in-query-string // we need to url encode token because token is not url safe var token = await _userManager.GeneratePasswordResetTokenAsync(user); RedirectResult redirectResult = new RedirectResult($"{_frontendConfiguration.BaseUrl}{_frontendConfiguration.AuthenticationControllerName}" + $"{_frontendConfiguration.ForgotPasswordActionName}?email={user.Email}&token={HttpUtility.UrlEncode(token)}"); var message = new Message(user.Email, "Reset password token", redirectResult.Url, redirectResult.Url); await _emailSender.SendEmail(message); return(Ok()); }
public IActionResult ForgotPassword(UserForForgotPasswordDto userForForgotPasswordDto) { if (!ModelState.IsValid) { return(View(new AccountViewModel { userForForgotPasswordDto = userForForgotPasswordDto })); } var result = _authService.SendPasswordResetMail(userForForgotPasswordDto); if (result.Success) { TempData.Add("message", "E-Mail ist gesendet"); return(RedirectToAction("ForgotPasswordEmailSent", "Account")); } ModelState.AddModelError("", result.Message); return(View(new AccountViewModel { userForForgotPasswordDto = userForForgotPasswordDto })); }
// [TransactionScopeAspect] public IResult SendPasswordResetMail(UserForForgotPasswordDto userForForgotPasswordDto) { var user = _userService.FindByEmail(userForForgotPasswordDto.Email); if (user == null) { return(new ErrorResult("User not found")); } var confirmationCode = _userService.GeneratePasswordResetToken(user); var callBackUrl = CreateConfirmationCode(user.UserName, confirmationCode, "ResetPassword"); _mailService.SendResetPasswordMail(callBackUrl, new string[] { user.Email }); return(new SuccessResult()); }
public async Task <IActionResult> ForgotPassword(UserForForgotPasswordDto userForForgotPasswordDto) { return(Ok(new { })); }