Cleaned up code a bit
这个提交包含在:
父节点
9037bf8dad
当前提交
c33ce3fdbb
共有 1 个文件被更改,包括 291 次插入 和 266 次删除
|
|
@ -1,6 +1,7 @@
|
|||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
class User extends CI_Controller {
|
||||
class User extends CI_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
|
@ -14,23 +15,39 @@ class User extends CI_Controller {
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Index method for the User controller.
|
||||
* This method loads the user model, authorizes the user, and displays the user accounts.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
|
||||
// Check if the user is authorized
|
||||
if (!$this->user_model->authorize(99)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
// Get the user accounts
|
||||
$data['results'] = $this->user_model->users();
|
||||
|
||||
// Set the page title
|
||||
$data['page_title'] = $this->lang->line('admin_user_accounts');
|
||||
|
||||
// Load the views
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('user/main');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
|
||||
function add() {
|
||||
function add()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (!$this->user_model->authorize(99)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
$data['existing_languages'] = $this->find();
|
||||
|
||||
|
|
@ -159,7 +176,8 @@ class User extends CI_Controller {
|
|||
}
|
||||
$this->load->view('interface_assets/footer');
|
||||
} else {
|
||||
switch($this->user_model->add($this->input->post('user_name'),
|
||||
switch ($this->user_model->add(
|
||||
$this->input->post('user_name'),
|
||||
$this->input->post('user_password'),
|
||||
$this->input->post('user_email'),
|
||||
$this->input->post('user_type'),
|
||||
|
|
@ -248,7 +266,8 @@ class User extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
function find() {
|
||||
function find()
|
||||
{
|
||||
$existing_langs = array();
|
||||
$lang_path = APPPATH . 'language';
|
||||
|
||||
|
|
@ -264,9 +283,13 @@ class User extends CI_Controller {
|
|||
return $dirs;
|
||||
}
|
||||
|
||||
function edit() {
|
||||
function edit()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if ( ($this->session->userdata('user_id') == '') || ((!$this->user_model->authorize(99)) && ($this->session->userdata('user_id') != $this->uri->segment(3))) ) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (($this->session->userdata('user_id') == '') || ((!$this->user_model->authorize(99)) && ($this->session->userdata('user_id') != $this->uri->segment(3)))) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
$data['existing_languages'] = $this->find();
|
||||
|
|
@ -276,8 +299,7 @@ class User extends CI_Controller {
|
|||
|
||||
$this->form_validation->set_rules('user_name', 'Username', 'required|xss_clean');
|
||||
$this->form_validation->set_rules('user_email', 'E-mail', 'required|xss_clean');
|
||||
if($this->session->userdata('user_type') == 99)
|
||||
{
|
||||
if ($this->session->userdata('user_type') == 99) {
|
||||
$this->form_validation->set_rules('user_type', 'Type', 'required|xss_clean');
|
||||
}
|
||||
$this->form_validation->set_rules('user_firstname', 'First name', 'required|xss_clean');
|
||||
|
|
@ -295,8 +317,7 @@ class User extends CI_Controller {
|
|||
// Get timezones
|
||||
$data['timezones'] = $this->user_model->timezones();
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data['page_title'] = "Edit User";
|
||||
|
||||
$q = $query->row();
|
||||
|
|
@ -661,7 +682,8 @@ class User extends CI_Controller {
|
|||
$data['map_icon_select'] = array(
|
||||
'station' => array('0', 'fas fa-home', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle'),
|
||||
'qso' => array('fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle'),
|
||||
'qsoconfirm'=>array('0', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle', 'fas fa-check-circle' ));
|
||||
'qsoconfirm' => array('0', 'fas fa-broadcast-tower', 'fas fa-user', 'fas fa-dot-circle', 'fas fa-check-circle')
|
||||
);
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('user/edit', $data);
|
||||
|
|
@ -793,9 +815,13 @@ class User extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
function profile() {
|
||||
function profile()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (!$this->user_model->authorize(2)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
$query = $this->user_model->get_by_id($this->session->userdata('user_id'));
|
||||
$q = $query->row();
|
||||
$data['page_title'] = "Profile";
|
||||
|
|
@ -827,9 +853,13 @@ class User extends CI_Controller {
|
|||
*
|
||||
* @param int $id The ID of the user to delete.
|
||||
*/
|
||||
function delete_new($id) {
|
||||
function delete_new($id)
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (!$this->user_model->authorize(99)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
// call $this->user_model->delete and if no errors return true
|
||||
|
|
@ -840,12 +870,15 @@ class User extends CI_Controller {
|
|||
// request responds with a 500 status code and empty content
|
||||
$this->output->set_status_header(500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function delete() {
|
||||
function delete()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (!$this->user_model->authorize(99)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
|
@ -854,17 +887,13 @@ class User extends CI_Controller {
|
|||
|
||||
$data = $query->row();
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
|
||||
$this->load->view('interface_assets/header', $data);
|
||||
$this->load->view('user/delete');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->user_model->delete($data->user_id))
|
||||
{
|
||||
} else {
|
||||
if ($this->user_model->delete($data->user_id)) {
|
||||
$this->session->set_flashdata('notice', 'User deleted');
|
||||
redirect('user');
|
||||
} else {
|
||||
|
|
@ -874,7 +903,8 @@ class User extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
function login() {
|
||||
function login()
|
||||
{
|
||||
// Check our version and run any migrations
|
||||
$this->load->library('Migration');
|
||||
$this->load->library('encryption');
|
||||
|
|
@ -915,7 +945,6 @@ class User extends CI_Controller {
|
|||
$this->load->view('interface_assets/mini_header', $data);
|
||||
$this->load->view('user/login');
|
||||
$this->load->view('interface_assets/footer');
|
||||
|
||||
} else {
|
||||
if ($this->user_model->login() == 1) {
|
||||
$this->session->set_flashdata('notice', 'User logged in');
|
||||
|
|
@ -951,7 +980,8 @@ class User extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
function logout()
|
||||
{
|
||||
$this->load->model('user_model');
|
||||
|
||||
$user_name = $this->session->userdata('user_name');
|
||||
|
|
@ -971,7 +1001,8 @@ class User extends CI_Controller {
|
|||
* Allows users to input an email address and a password will be sent to that address.
|
||||
*
|
||||
*/
|
||||
function forgot_password() {
|
||||
function forgot_password()
|
||||
{
|
||||
|
||||
$this->load->helper(array('form', 'url'));
|
||||
|
||||
|
|
@ -979,15 +1010,12 @@ class User extends CI_Controller {
|
|||
|
||||
$this->form_validation->set_rules('email', 'Email', 'required');
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data['page_title'] = "Forgot Password";
|
||||
$this->load->view('interface_assets/mini_header', $data);
|
||||
$this->load->view('user/forgot_password');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Check email address exists
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
|
@ -1006,7 +1034,7 @@ class User extends CI_Controller {
|
|||
$this->load->library('email');
|
||||
|
||||
if ($this->optionslib->get_option('emailProtocol') == "smtp") {
|
||||
$config = Array(
|
||||
$config = array(
|
||||
'protocol' => $this->optionslib->get_option('emailProtocol'),
|
||||
'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'),
|
||||
'smtp_host' => $this->optionslib->get_option('smtpHost'),
|
||||
|
|
@ -1028,8 +1056,7 @@ class User extends CI_Controller {
|
|||
$this->email->subject('Cloudlog Account Password Reset');
|
||||
$this->email->message($message);
|
||||
|
||||
if (! $this->email->send())
|
||||
{
|
||||
if (!$this->email->send()) {
|
||||
// Redirect to login page with message
|
||||
$this->session->set_flashdata('warning', 'Email settings are incorrect.');
|
||||
redirect('user/login');
|
||||
|
|
@ -1047,10 +1074,14 @@ class User extends CI_Controller {
|
|||
}
|
||||
|
||||
// Send an E-Mail to the user. Function is similar to forgot_password()
|
||||
function admin_send_passwort_reset() {
|
||||
function admin_send_passwort_reset()
|
||||
{
|
||||
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
if (!$this->user_model->authorize(99)) {
|
||||
$this->session->set_flashdata('notice', 'You\'re not allowed to do that!');
|
||||
redirect('dashboard');
|
||||
}
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
|
@ -1059,13 +1090,10 @@ class User extends CI_Controller {
|
|||
|
||||
$data = $query->row();
|
||||
|
||||
if ($this->form_validation->run() != FALSE)
|
||||
{
|
||||
if ($this->form_validation->run() != FALSE) {
|
||||
$this->session->set_flashdata('notice', 'Something went wrong! User has no user_id.');
|
||||
redirect('user');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Check email address exists
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
|
@ -1086,7 +1114,7 @@ class User extends CI_Controller {
|
|||
$this->load->library('email');
|
||||
|
||||
if ($this->optionslib->get_option('emailProtocol') == "smtp") {
|
||||
$config = Array(
|
||||
$config = array(
|
||||
'protocol' => $this->optionslib->get_option('emailProtocol'),
|
||||
'smtp_crypto' => $this->optionslib->get_option('smtpEncryption'),
|
||||
'smtp_host' => $this->optionslib->get_option('smtpHost'),
|
||||
|
|
@ -1107,8 +1135,7 @@ class User extends CI_Controller {
|
|||
$this->email->subject('Cloudlog Account Password Reset');
|
||||
$this->email->message($message);
|
||||
|
||||
if (! $this->email->send())
|
||||
{
|
||||
if (!$this->email->send()) {
|
||||
// Redirect to user page with message
|
||||
$this->session->set_flashdata('danger', lang('admin_email_settings_incorrect'));
|
||||
redirect('user');
|
||||
|
|
@ -1136,15 +1163,12 @@ class User extends CI_Controller {
|
|||
$this->form_validation->set_rules('password', 'Password', 'required');
|
||||
$this->form_validation->set_rules('password_confirm', 'Password Confirmation', 'required|matches[password]');
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
if ($this->form_validation->run() == FALSE) {
|
||||
$data['page_title'] = "Reset Password";
|
||||
$this->load->view('interface_assets/mini_header', $data);
|
||||
$this->load->view('user/reset_password');
|
||||
$this->load->view('interface_assets/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Lets reset the password!
|
||||
$this->load->model('user_model');
|
||||
|
||||
|
|
@ -1157,7 +1181,8 @@ class User extends CI_Controller {
|
|||
}
|
||||
}
|
||||
|
||||
function check_locator($grid) {
|
||||
function check_locator($grid)
|
||||
{
|
||||
$grid = $this->input->post('user_locator');
|
||||
// Allow empty locator
|
||||
if (preg_match('/^$/', $grid)) return true;
|
||||
|
|
|
|||
正在加载…
在新工单中引用