From 7156b185e1b192e66c87b94a85b25231fb8175e7 Mon Sep 17 00:00:00 2001 From: Peter Goodhall Date: Wed, 28 May 2025 13:38:25 +0100 Subject: [PATCH] add option to turn on websockets for winkey --- application/config/migration.php | 2 +- application/controllers/User.php | 33 +++++++++++++------ .../migrations/197_add_winkey_websocket.php | 30 +++++++++++++++++ application/models/User_model.php | 1 + application/views/user/edit.php | 5 +-- 5 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 application/migrations/197_add_winkey_websocket.php diff --git a/application/config/migration.php b/application/config/migration.php index ce5a1727..90c77c9d 100644 --- a/application/config/migration.php +++ b/application/config/migration.php @@ -22,7 +22,7 @@ $config['migration_enabled'] = TRUE; | */ -$config['migration_version'] = 196; +$config['migration_version'] = 197; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/User.php b/application/controllers/User.php index d3b91646..42c6808b 100644 --- a/application/controllers/User.php +++ b/application/controllers/User.php @@ -22,7 +22,7 @@ class User extends CI_Controller public function index() { $this->load->model('user_model'); - + // Check if the user is authorized if (!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); @@ -215,7 +215,7 @@ class User extends CI_Controller $this->input->post('user_callbook_username'), $this->input->post('user_callbook_password') )) { - // Check for errors + // Check for errors case EUSERNAMEEXISTS: $data['username_error'] = 'Username ' . $this->input->post('user_name') . ' already in use!'; break; @@ -225,7 +225,7 @@ class User extends CI_Controller case EPASSWORDINVALID: $data['password_error'] = 'Invalid password!'; break; - // All okay, return to user screen + // All okay, return to user screen case OK: $this->session->set_flashdata('notice', 'User ' . $this->input->post('user_name') . ' added'); redirect('user'); @@ -576,6 +576,12 @@ class User extends CI_Controller $data['user_winkey'] = $q->winkey; } + if ($this->input->post('user_winkey_websocket')) { + $data['user_winkey_websocket'] = $this->input->post('user_winkey_websocket', true); + } else { + $data['user_winkey_websocket'] = $q->winkey_websocket; + } + $this->load->model('user_options_model'); $callbook_type_object = $this->user_options_model->get_options('callbook')->result(); @@ -730,8 +736,14 @@ class User extends CI_Controller $this->load->view('interface_assets/footer'); } else { unset($data); - switch ($this->user_model->edit($this->input->post())) { - // Check for errors + + + $post_data = $this->input->post(); + if (!isset($post_data['user_winkey_websocket'])) { + $post_data['user_winkey_websocket'] = '0'; + } + switch ($this->user_model->edit($post_data)) { + // Check for errors case EUSERNAMEEXISTS: $data['username_error'] = 'Username ' . $this->input->post('user_name', true) . ' already in use!'; break; @@ -741,7 +753,7 @@ class User extends CI_Controller case EPASSWORDINVALID: $data['password_error'] = 'Invalid password!'; break; - // All okay, return to user screen + // All okay, return to user screen case OK: if ($this->session->userdata('user_id') == $this->uri->segment(3)) { // Editing own User? Set cookie! $cookie = array( @@ -755,25 +767,25 @@ class User extends CI_Controller $this->input->set_cookie($cookie); } if ($this->session->userdata('user_id') == $this->input->post('id', true)) { - + // Handle user_callbook_password if (isset($_POST['user_callbook_password']) && !empty($_POST['user_callbook_password'])) { - + // Handle user_callbook_type if (isset($_POST['user_callbook_type'])) { $this->user_options_model->set_option('callbook', 'callbook_type', array('value' => $_POST['user_callbook_type'])); } else { $this->user_options_model->set_option('callbook', 'callbook_type', array('value' => '')); } - + // Handle user_callbook_username if (isset($_POST['user_callbook_username'])) { $this->user_options_model->set_option('callbook', 'callbook_username', array('value' => $_POST['user_callbook_username'])); } else { $this->user_options_model->set_option('callbook', 'callbook_username', array('value' => '')); } - + // Load the encryption library $this->load->library('encryption'); @@ -892,6 +904,7 @@ class User extends CI_Controller $data['user_quicklog_enter'] = $this->input->post('user_quicklog_enter'); $data['language'] = $this->input->post('language'); $data['user_winkey'] = $this->input->post('user_winkey'); + $data['user_winkey_websocket'] = $this->input->post('user_winkey_websocket'); $data['user_hamsat_key'] = $this->input->post('user_hamsat_key'); $data['user_hamsat_workable_only'] = $this->input->post('user_hamsat_workable_only'); diff --git a/application/migrations/197_add_winkey_websocket.php b/application/migrations/197_add_winkey_websocket.php new file mode 100644 index 00000000..a38b9a75 --- /dev/null +++ b/application/migrations/197_add_winkey_websocket.php @@ -0,0 +1,30 @@ +db->field_exists('winkey_websocket', 'users')) { + $fields = array( + 'winkey_websocket boolean default 0', + ); + + $this->dbforge->add_column('users', $fields); + } + } + + public function down() + { + if ($this->db->field_exists('winkey_websocket', 'users')) { + $this->dbforge->drop_column('users', 'winkey_websocket'); + } + } +} diff --git a/application/models/User_model.php b/application/models/User_model.php index 3a12405b..aeb20967 100644 --- a/application/models/User_model.php +++ b/application/models/User_model.php @@ -267,6 +267,7 @@ class User_Model extends CI_Model { 'user_quicklog_enter' => xss_clean($fields['user_quicklog_enter']), 'language' => xss_clean($fields['language']), 'winkey' => xss_clean($fields['user_winkey']), + 'winkey_websocket' => xss_clean($fields['user_winkey_websocket']), ); $this->db->query("replace into user_options (user_id, option_type, option_name, option_key, option_value) values (" . $fields['id'] . ", 'hamsat','hamsat_key','api','".xss_clean($fields['user_hamsat_key'])."');"); diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 5d5f032d..33b2b4e1 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -1205,10 +1205,7 @@
- - >