public async Task <IActionResult> SignIn(SignInDTOModel model) { try { if (!ModelState.IsValid) { return(View()); } var user = _userRepository.Get(model); if (!user.IsConfirmed) { ViewBag.Error = "Подтвердите почту! Сообщение было отправлено вам на почту."; return(View()); } var auth = new AuthModel { Id = user.Id, Guid = Guid.NewGuid().ToString() }; _cookieProvider.UpdateGuidInCookies(HttpContext, auth.Guid); _authRepository.UpdateOne(auth); await Authenticate(String.Format("{0} {1}", user.FirstName, user.LastName)); return(Redirect("/Home")); } catch (Exception ex) { ViewBag.Error = "Пользователь с такими данными не найден"; return(View()); } }
public User Get(SignInDTOModel model) { var user = _doc.Find(x => x.Login == model.Login && x.Password == model.Password); if (user == null || !user.Any()) { throw new Exception("User not found!"); } return(user.First()); }