diff --git a/application/controllers/User.php b/application/controllers/User.php index e6fbbdd58..724be3992 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -25,6 +25,12 @@ class User extends CI_Controller { $data['disable_impersonate'] = false; } + if ($this->config->item('max_login_attempts')) { + $data['maxattempts'] = $this->config->item('max_login_attempts'); + } else { + $data['maxattempts'] = 3; + } + // Get Date format if($this->session->userdata('user_date_format')) { // If Logged in and session exists @@ -63,6 +69,12 @@ class User extends CI_Controller { $custom_date_format = $this->config->item('qso_date_format'); } + if ($this->config->item('max_login_attempts')) { + $maxattempts = $this->config->item('max_login_attempts'); + } else { + $maxattempts = 3; + } + if ($this->user_model->exists_by_id($data['user_id']) && $modal != '') { $user = $this->user_model->get_by_id($data['user_id'])->row(); $gettext = new Gettext; @@ -74,6 +86,7 @@ class User extends CI_Controller { $data['user_lastname'] = $user->user_lastname; $data['user_language'] = $gettext->find_by('folder', $user->user_language)['name_en']; $data['is_clubstation'] = $user->clubstation == 1 ? true : false; + $data['is_locked'] = $user->login_attempts > $maxattempts ? true : false; $data['last_seen'] = $user->last_seen; $data['custom_date_format'] = $custom_date_format; $data['has_flossie'] = ($this->config->item('encryption_key') == 'flossie1234555541') ? true : false; @@ -85,6 +98,24 @@ class User extends CI_Controller { } } + public function unlock($uid) { + $this->load->model('user_model'); + if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } + + if ($this->user_model->exists_by_id($uid)) { + if ($this->user_model->unlock($uid)) { + $this->session->set_flashdata('success', __("User unlocked!")); + redirect('user'); + } else { + $this->session->set_flashdata('error', __("Failed to unlock user!")); + redirect('user'); + } + } else { + $this->session->set_flashdata('error', __("User not found!")); + redirect('dashboard'); + } + } + public function convert() { $this->load->model('user_model'); if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('error', __("You're not allowed to do that!")); redirect('dashboard'); } diff --git a/application/models/User_model.php b/application/models/User_model.php index 597043d29..23aa6df9b 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -672,6 +672,12 @@ class User_Model extends CI_Model { } } + // FUNCTION: bool unlock($user_id) + // Unlocks a user account after it was locked doe too many failed login attempts + function unlock($user_id) { + return $this->db->query("UPDATE users SET login_attempts = 0 WHERE user_id = ?", [$user_id]); + } + // FUNCTION: object users() // Returns a list of users with additional counts function users($club = '') { diff --git a/application/views/user/index.php b/application/views/user/index.php index cb56c254d..8d0e83403 100644 --- a/application/views/user/index.php +++ b/application/views/user/index.php @@ -70,17 +70,21 @@ } ?>