public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordEmail data) { if (data == null) { return(new JsonResult("Input Invalid")); } string email = data.email; var user = await _userManager.FindByEmailAsync(email); if (user != null) { try { var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPasswordEmail", "Accounts", new { UserId = user.Id, Code = code }, protocol: HttpContext.Request.Scheme); var send = await _emailsender.SendEmailAsync(user.Email, "younesco.com - Reset Your Password", "Please reset your password by clicking this link: <a href=\"" + callbackUrl + "\">click here</a>"); return(Ok(new { username = user.UserName, email = user.Email, status = 1, message = "Reset Password Email Was Sent To " + email + " !" })); } catch (Exception ex) { _exceptionLogger.saveExceptionLog(user.Id, "Account Forgot Password", ex.Message); return(BadRequest(new JsonResult("Failed to send password reset token Email. Response : " + ex.Message))); } } return(new JsonResult("Email Does Not Exists!")); }
public async Task <bool> SendForgotPasswordEmail(ForgotPasswordEmail forgotPasswordEmail) { try { using (httpClient) { StringContent content = CreateEmailJsonObject(forgotPasswordEmail); var emailResponse = await httpClient.PostAsync("accounts/forgotpassword", content); if (!emailResponse.IsSuccessStatusCode) { var responseContent = await emailResponse.Content.ReadAsStringAsync(); logger.LogWarning(string.Format("Error in Sending ForgotPasswordEmail. Reason: {0}. Response Content: {1}", emailResponse.ReasonPhrase, responseContent)); return(false); } return(true); } } catch (Exception ex) { logger.LogError(string.Format("Error in EmailProvider - SendForgotPasswordEmail. {0}", ex.Message)); return(false); } }
public async void RequestPasswordReset(User user) { var token = await _userManager.GeneratePasswordResetTokenAsync(user); var mailBuilder = new ForgotPasswordEmail(_mailConfig); var mail = mailBuilder.Build("/localhost/api/auth/" + token, new MailAddress(user.Email, user.UserName)); _mailService.Send(mail); }
public async Task <IActionResult> ForgotPassword([FromBody] ForgotPasswordEmail brain) { string email = brain.email; var user = await _userManager.FindByEmailAsync(email); if (user != null) { var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action("ResetPasswordEmail", "Account", new { UserId = user.Id, Code = code }, protocol: HttpContext.Request.Scheme); await _emailsender.SendEmailAsync(user.Email, "MyClinic.com - Reset Your Password", "Please reset your password by clicking this link: <a href=\"" + callbackUrl + "\">click here</a>"); return(Ok(new { username = user.UserName, email = user.Email, status = 1, message = "Reset Password Email Was Sent To " + email + " !" })); } return(new JsonResult("Email Does Not Exists!")); }