protected bool ValidateModel(LoginRecoveryModel model) { return ModelState.IsValid; }
public ActionResult LoginRecovery() { LoginRecoveryModel model = new LoginRecoveryModel{Subject = string.Empty,Text = string.Empty}; return View(model); }
public ActionResult LoginRecovery(LoginRecoveryModel model) { if (!ValidateModel(model)) return View(model); LoginBl.OnLoginRecovery(model); //if (model.EmailDto != null) //{ // if (string.IsNullOrEmpty(model.EmailDto.Error)) // SendEmail(model.EmailDto); // if (!string.IsNullOrEmpty(model.EmailDto.Error)) // ModelState.AddModelError("", // string.Format(@"Пароль не был отправлен на электронную почту пользователя.Ошибка - {0}.", model.EmailDto.Error)); // return View(model); //} if (!string.IsNullOrEmpty(model.Error)) { ModelState.AddModelError("", model.Error); return View(model); } model.IsRecoverySuccess = true; return View(model); }
public void OnLoginRecovery(LoginRecoveryModel model) { try { IList<User> alter = UserDao.QueryExpression(x => x.AlternativeMail == model.Email); IList<User> users = UserDao.FindByEmail(model.Email); if (users.Count == 0 && !alter.Any()) { model.Error = "Не найден пользователь с таким адресом электронной почты."; //model.IsSupportFormVisible = true; model.Subject = string.Empty; model.Text = string.Empty; return; } //if (!user.IsActive) //{ // model.Error = // "Пользователь с данным логином неактивен.Вы можете обратиться в тех. поддержку через форму ниже."; // model.IsSupportFormVisible = true; // model.Subject = string.Empty; // model.Text = string.Empty; // return; //} //if (string.IsNullOrEmpty(user.Email)) //{ // model.Error = // "У пользователя с данным логином не указан e-mail.Вы можете обратиться в тех. поддержку через форму ниже."; // model.IsSupportFormVisible = true; // model.Subject = string.Empty; // model.Text = string.Empty; // return; //} string message = string.Format("Информация для пользователя с адресом электронной почты {0}:<br/>",model.Email); if(users.Any()) message = users.Aggregate(message, (current, user) => current + string.Format("Логин {0} - пароль {1}<br/>", user.Login, user.Password)); else message = alter.Aggregate(message, (current, user) => current + string.Format("Логин {0} - пароль {1}<br/>", user.Login, user.Password)); SendEmail(model,/*EmailType.UserPasswordRecovered,*/ model.Email, "Восстановление пароля", message); if (!string.IsNullOrEmpty(model.EmailDto.Error)) { model.Error = "Ошибка при отправке письма: " + model.EmailDto.Error; //" Вы можете обратиться в тех. поддержку через форму ниже."; //model.IsSupportFormVisible = true; //model.Subject = string.Empty; //model.Text = string.Empty; } else model.IsRecoverySuccess = true; //model.Error = "Пароль отправлен на e-mail пользователя."; } catch (Exception ex) { Log.Error("Exception:", ex); model.Error = string.Format("Исключение:{0}", ex.GetBaseException().Message); } }