public async Task <ActionResult> ForgotPassword(AccountEmailModel model) { if (!ModelState.IsValid) { } var callbackUrl = Url.Action("ResetPassword", "Account", new { email = "{0}", code = "{1}" }, Request.Url.Scheme); model.CallbackUrl = callbackUrl; await _membershipService.ForgotPasswordAsync(model.Email, model.CallbackUrl); return(View(model)); }
public async Task <IHttpActionResult> ForgotPassword([FromBody] AccountEmailModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null || !(await _userManager.IsEmailConfirmedAsync(user.Id))) { ModelState.AddModelError("", "User not found or email is not confirmed"); return(BadRequest(ModelState)); } string code = await _userManager.GeneratePasswordResetTokenAsync(user.Id); string callbackUrl = string.Format(WebUtility.UrlDecode(model.CallbackUrl), model.Email, WebUtility.UrlEncode(code)); await _userManager.SendEmailAsync(user.Id, "Password Reset", LoadTemplate(callbackUrl, "password-reset.html")); return(Ok()); } return(BadRequest(ModelState)); }