コード例 #1
0
ファイル: UserManager.cs プロジェクト: dmitr12/DiplomProject
        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));
            }
        }
コード例 #2
0
 public IActionResult EmailForgotPassword(EmailForgotPassword model)
 {
     return(userManager.SendEmailForgotPassword(model, $"{Request.Scheme}://{Request.Host.Value}").Result);
 }