public void SendMailLostPassword(LostPasswordDto infos) { Logger.LogInformation($"Send a mail password lost to {infos.Email}"); Validate(infos); using (var context = RepositoriesFactory.CreateContext()) { var errorResource = this.GetErrorStringLocalizer(); var mailResource = this.GetMailStringLocalizer(); var userRepo = RepositoriesFactory.GetUserRepository(context); var user = userRepo.GetByEmail(infos.Email); if (user == null || !user.IsValid) { throw new DaOAuthServiceException(errorResource["SendMailLostPasswordUserNoUserFound"]); } var myToken = JwtService.GenerateMailToken(user.UserName); var link = new Uri(String.Format(Configuration.GetNewPasswordPageUrl, myToken.Token)); MailService.SendEmail(new SendEmailDto() { Body = String.Format(mailResource["MailLostPasswordBody"], link.AbsoluteUri), IsHtml = true, Receviers = new Dictionary <string, string>() { { user.EMail, user.EMail } }, Sender = new KeyValuePair <string, string>("*****@*****.**", "no reply"), Subject = mailResource["MailLostPasswordSubject"] }); } }
public IActionResult GetNewPassword(string email) { var model = new LostPasswordDto() { Email = email }; _service.SendMailLostPassword(model); return(Ok()); }