public ActionResult LogOn(UserLogOnViewModel userLogOnViewModel) { if (ModelState.IsValid) { try { var auth = new Tigwi.Auth.PasswordAuth(RawStorage, userLogOnViewModel.Login, userLogOnViewModel.Password); Guid userId = auth.Authenticate(); var loggingUser = this.Storage.Users.Find(userLogOnViewModel.Login); this.AuthenticateUser(loggingUser, userLogOnViewModel.RememberMe); return(this.RedirectToAction("Index", "Home")); // return this.RedirectToAction("Timeline", "Account"); } catch (Tigwi.Auth.AuthFailedException) { ModelState.AddModelError("Login", "Bad login/password"); } catch (UserNotFoundException ex) { ModelState.AddModelError("Login", ex.Message); } } return(this.View(userLogOnViewModel)); }
public Guid GetOrganizationInfoByUser(UserLogOnViewModel user) { var temp = _identityDbContext.ApplicationUsers.SingleOrDefault(s => s.Email == user.Email); //_applicationDbContext.Organizations.Include("Employees"); var emp = _applicationDbContext.Employees.SingleOrDefault(s => s.Id == temp.AssosiatedEmployeeId); var model = _applicationDbContext.Organizations.SingleOrDefault(s => s.Id == emp.OrganizationId); return(model.Id); }
public static UserLogOnViewModel UserInfoForRegistration() { UserLogOnViewModel model = new UserLogOnViewModel(); Console.WriteLine("Введите email"); model.Email = Console.ReadLine(); Console.WriteLine("Введите пароль"); model.Password = Console.ReadLine(); return(model); }
private bool IsValidUser(UserLogOnViewModel model) { model.GeoLocation = GeoLocationInfo.GetGeolocationInfo(); //проверяем, есть ли емейл в базе var user = _identityDbContext.ApplicationUsers.Include("ApplicationUserPasswordHistories") .SingleOrDefault(p => p.Email == model.Email); if (user == null) { throw new Exception($"Пользователя с email {model.Email} нет в базе"); } //проверяем, подходит ли пароль емейлу var userPassword = user.ApplicationUserPasswordHistories.SingleOrDefault(p => p.Password == model.Password); if (userPassword == null) { user.FailedSignInCount += 1; _identityDbContext.SaveChanges(); throw new Exception("Неверный пароль"); } if (userPassword != null && userPassword.InvalidatedDate != null) { user.FailedSignInCount += 1; _identityDbContext.SaveChanges(); throw new Exception("Аккаунт пользователя заблокирован"); } //добавляем строку нового входа в таблице ApplicationUserSignInHistories в БД ApplicationUserSignInHistory userSignInHistory = new ApplicationUserSignInHistory() { Id = Guid.NewGuid(), ApplicationUserId = user.Id, SignInTime = DateTime.Now, MachineIp = model.GeoLocation.ip, IpToGeoCountry = model.GeoLocation.country_name, IpToGeoCity = model.GeoLocation.city, IpToGeoLatitude = model.GeoLocation.latitude, IpToGeoLongitude = model.GeoLocation.longitude }; _identityDbContext.ApplicationUserSignInHistories.Add(userSignInHistory); _identityDbContext.SaveChanges(); return(true); }