public async Task SendForgotPasswordAsync(ForgotPasswordEmailModel model) { await SendEmailAsync(new EmailModel { ToEmail = model.Email, ToName = model.FirstName, Subject = "Forgot Password", Body = $"<a href={_appSettings.WebUrl}/reset-password?token={model.ResetPasswordToken}>Link</a> to reset password." }); }
public async Task <bool> SendForgotPasswordEmail(string accountEmail, string resetToken, Func <bool> canNotifyUser) { _logger.LogInformation("Sending password reset email"); if (!canNotifyUser()) { _logger.LogInformation("User has not consented to receiving emails, email not sent"); } if (string.IsNullOrWhiteSpace(accountEmail)) { _logger.LogWarning("Missing parameter {Parameter}, password reset email not sent", nameof(accountEmail)); return(false); } if (string.IsNullOrWhiteSpace(resetToken)) { _logger.LogWarning("Missing parameter {Parameter}, password reset email not sent", nameof(resetToken)); return(false); } try { var model = new ForgotPasswordEmailModel() { BaseUrl = _url, Title = "CoreWiki Password Reset", ReturnUrl = $"{_url}Identity/Account/ResetPassword?code={resetToken}", AccountEmail = accountEmail }; var messageBody = await _emailMessageFormatter.FormatEmailMessage( TemplateProvider.ForgotPasswordEmailTemplate, model); return(await _emailNotifier.SendEmailAsync( accountEmail, "CoreWiki Password Reset", messageBody)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); #if DEBUG throw; #else return(false); #endif } }
public ActionResult ForgotPasswordEmailLink(ForgotPasswordEmailModel forgotPasswordEmailModel) { try { _userManager.Validate(forgotPasswordEmailModel.Token); return(RedirectToAction("Index", "Profile")); } catch (BusinessException be) { ///TODO Log error. return(RedirectToAction("Index", "Error")); } }
public IHttpActionResult GetForgotPassword(UserMail userMail) { if (userMail == null || string.IsNullOrEmpty(userMail.Mail) || string.IsNullOrWhiteSpace(userMail.Mail)) { return(NotFound()); } var user = db.Users.FirstOrDefault(u => u.Email.Trim().ToLower() == userMail.Mail.Trim().ToLower()); if (user == null) { return(NotFound()); } EmailService emailService = new EmailService(); ForgotPasswordEmailModel model = new ForgotPasswordEmailModel { Name = user.UserName, Password = Protector.Decrypt(user.Password) }; var templateService = new RazorEngine.Templating.TemplateService(); var templateFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services", "Email", "ForgotPasswordEmailTemplate.cshtml"); var emailHtmlBody = templateService.Parse(File.ReadAllText(templateFilePath), model, null, null); try { IdentityMessage msg = new IdentityMessage(); msg.Subject = "Loglig"; msg.Body = emailHtmlBody; msg.Destination = user.Email; emailService.SendAsync(msg); } catch (Exception ex) { return(InternalServerError()); } return(Ok()); }