Example #1
0
 public async Task AddAuthHistory([FromBody] string action)
 {
     var history = new AuthHistory {
         UserLogin = User.Identity.Name, Action = action
     };
     await _service.AddAuthHistoryAsync(history);
 }
Example #2
0
        public static void LogoutStateSave(string user_id)
        {
            DatabaseContexts db = new DatabaseContexts();
            AuthHistory      ah = db.auth_history.Where(s => s.user_id == user_id && s.login_date.Day == DateTime.Now.Day && s.login_date.Month == s.login_date.Month && s.login_date.Year == DateTime.Now.Year).FirstOrDefault();

            if (ah != null)
            {
                ah.logout_date = DateTime.Now;
                db.SaveChanges();
            }
        }
 public async Task AddAuthHistoryAsync(AuthHistory history)
 {
     _context.AuthenticationHistory.Add(history);
     await _context.SaveChangesAsync();
 }
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            int count = 0;

            AuthHistory history = new AuthHistory();
            int         userId  = 0;

            foreach (var user in AutoserviceBaseEntities.getContext().User)
            {
                count++;
                if (txtBoxLogin.Text == user.Login && passBoxPassword.Password == user.Password || txtBoxPassword.Text == user.Password)
                {
                    Manager.firstName = user.FirstName;
                    Manager.lastName  = user.LastName;
                    foreach (var role in AutoserviceBaseEntities.getContext().Role)
                    {
                        if (user.RoleId == role.Id)
                        {
                            Manager.role = role.Name;
                        }
                    }
                    user.LastEnter = DateTime.Now;
                    userId         = user.Id;
                    MessageBox.Show("Вы успешно авторизованы.", "Информация!", MessageBoxButton.OK, MessageBoxImage.Information);
                    MainWindow mainWindow = new MainWindow();
                    mainWindow.Show();
                    count = 0;
                    this.Close();
                    break;
                }
                if (txtBoxLogin.Text == user.Login)
                {
                    userId = user.Id;
                }
            }
            if (count != 0)
            {
                MessageBox.Show("Логин или пароль не верны!", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Warning);
                try
                {
                    history.UserId   = userId;
                    history.DateTime = DateTime.Now;
                    history.Status   = "Blocked";
                    AutoserviceBaseEntities.getContext().AuthHistory.Add(history);
                    AutoserviceBaseEntities.getContext().SaveChanges();
                }
                catch
                {
                    MessageBox.Show("Ошибка записи истории входа в базу данных!\nПроверьте правильность введенных данных.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            countErrorAuths++;
            if (countErrorAuths % 3 == 0)
            {
                MessageBox.Show("Превышено количество попыток входа!\nПовторите попытку через 10 секунд.", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Warning);
                Thread.Sleep(10000);
            }
            try
            {
                if (!string.IsNullOrEmpty(txtBoxLogin.Text) && !string.IsNullOrEmpty(passBoxPassword.Password) && count == 0)
                {
                    history.UserId   = userId;
                    history.DateTime = DateTime.Now;
                    history.Status   = "Successfull";
                    AutoserviceBaseEntities.getContext().AuthHistory.Add(history);
                    AutoserviceBaseEntities.getContext().SaveChanges();
                }
            }
            catch
            {
                MessageBox.Show("Ошибка связи с базой данной!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
Example #5
0
 public async Task AddAuthHistoryAsync(AuthHistory history)
 {
     await _repository.AddAuthHistoryAsync(history);
 }