public async Task <ActionResult> ForgotPassword(string mail) { if (string.IsNullOrEmpty(mail) == false) { var user = await userRepository.GetUserByEmailAsync(mail); if (user != null) { try { EmailWorker emailWorker = new EmailWorker(); BuildingEmailBody body = new BuildingEmailBody(); string htmlBody = body.ForForgotPassword(this.Server.MapPath("~/Common/Email/HtmlBody/ForgotPassword.html"), "uid=" + user.ID.ToString()); await emailWorker.SendEmailAsync(user.Email.Mail, "Восстановление пароля", htmlBody); ViewBag.Success = "Письмо отправлено. В течение минуты оно придет к вам на почту."; letterRepository.CreateLetter(new Domain.Core.Letter { Date = DateTime.Now, EmailID = user.EmailID, LetterTypeID = 1 //Password recovery }); letterRepository.Save(); return(PartialView("_ForgotPasswordPartial")); } catch (Exception ex) { ViewBag.ErrorMessage = "Ошибка при отправке письма."; Log.Error(ex, "Ошибка при отправке почты."); return(PartialView("_ForgotPasswordPartial")); } } } ViewBag.NotExist = "Такой почты не существует"; return(PartialView("_ForgotPasswordPartial")); }
public async Task <ActionResult> ConfirmEmail_WillSendLetter() { var userProfile = UserStorage.Get(); if (userProfile != null) { try { EmailWorker emailWorker = new EmailWorker(); BuildingEmailBody body = new BuildingEmailBody(); string htmlBody = body.ForConfirmEmail(this.Server.MapPath("~/Common/Email/HtmlBody/ConfirmEmail.html"), "uid=" + userProfile.ID.ToString(), userProfile.Email.Mail); await emailWorker.SendEmailAsync(userProfile.Email.Mail, "Подтверждение почты1", htmlBody); ViewBag.Success = "Письмо отправлено. В течение минуты оно придет к вам на почту."; letterRepository.CreateLetter(new Domain.Core.Letter { Date = DateTime.Now, EmailID = userProfile.EmailID, LetterTypeID = 2 //Confirm email }); letterRepository.Save(); return(PartialView("_ForgotPasswordPartial")); } catch (Exception ex) { ViewBag.ErrorMessage = "Ошибка при отправке письма."; Log.Error(ex, "Ошибка при отправке почты."); return(PartialView("_ForgotPasswordPartial")); } } ViewBag.NotExist = "Авторизуйтесь"; return(PartialView("_ForgotPasswordPartial")); }