public async Task <IActionResult> SendEmailForgotPassword(EmailForgotPassword model, string baseUrl) { try { var user = await db.Users.Where(u => u.Mail == model.Email).FirstOrDefaultAsync(); if (user == null) { return(new NotFoundResult()); } if (!user.IsMailConfirmed) { return(new OkObjectResult(new { msg = "Почта не подтверждена" })); } var emailInfo = new EmailInfo(); emailInfo.Subject = "Заменя пароля в приложении MusicApp"; emailInfo.Body = $"<div><p>Кликните по ссылке ниже, чтобы заменить пароль</p><a href='{baseUrl}{forgotPasswordLink}/{user.UserId}/{user.VerifyCode}'>Заменить пароль</a></div>"; emailInfo.ToMails.Add(model.Email); var emailResult = emailManager.Send(emailInfo); if (emailResult.Sended) { return(new OkResult()); } return(new StatusCodeResult(500)); } catch { return(new StatusCodeResult(500)); } }
public IActionResult EmailForgotPassword(EmailForgotPassword model) { return(userManager.SendEmailForgotPassword(model, $"{Request.Scheme}://{Request.Host.Value}").Result); }