public async Task SendForgotPasswordEmail(ForgotPasswordNotificationUserDto model) { dynamic expando = new ExpandoObject(); expando.Subject = model.Subject; expando.Email = model.Email; expando.FullName = model.FullName; expando.Message = model.Message; var messageBodyHTML = _templateManager.GetTemplate(NotificationTemplateConst.Forgot_Password, expando); string emailTemplateFolder = Path.Combine(_webHostEnvironment.WebRootPath, Path.Combine("images", "email")); List <string> attachmentList = new List <string>(); attachmentList.Add(Path.Combine(emailTemplateFolder, "logo.png")); var emailDto = new EmailDto() { FromConst = NotificationFromConst.Info, EmailTo = model.Email, EmailSubject = model.Subject, EmailBody = messageBodyHTML, AttachmentInBodyList = attachmentList, }; await _emailService.SendEmailAsync(emailDto); }
public async Task <IActionResult> ForgotPassword(ForgotPasswordRequest model) { var user = await _userManager.FindByEmailAsync(model.Email); //always return ok response to prevent email enumeration if (user == null) { ModelState.TryAddModelError("InValidEmail", L("InvalidEmailAddress")); return(View(model)); } if (!user.IsEmailConfirmed) { ModelState.TryAddModelError("InValidEmail", L("UserEmailIsNotConfirmedAndResetPassword")); return(View(model)); } if (!user.IsActive) { ModelState.TryAddModelError("InvalidUserNameOrPassword", string.Format(L("UserIsNotActiveAndCanNotResetPassword"), user.FullName)); return(View(model)); } var code = await _userManager.GeneratePasswordResetTokenAsync(user); var callbackUrl = Url.Action(nameof(ResetPassword), "Account", new { token = code, email = model.Email }, protocol: HttpContext.Request.Scheme); var forgotPassworNotificationdDto = new ForgotPasswordNotificationUserDto() { FullName = user.FullName, Email = user.EmailAddress, Message = callbackUrl, Subject = "Forgot Password" }; await _notificationManager.SendForgotPasswordEmail(forgotPassworNotificationdDto); return(RedirectToAction(nameof(ForgotPasswordConfirmation))); }