Controller work for user functions
这个提交包含在:
父节点
28ee178dd1
当前提交
5a003c5665
共有 4 个文件被更改,包括 100 次插入 和 26 次删除
|
|
@ -71,6 +71,8 @@ class API extends CI_Controller {
|
|||
// Load the API and Logbook models
|
||||
$this->load->model('api_model');
|
||||
$this->load->model('logbook_model');
|
||||
$this->load->model('user_model');
|
||||
if(!$this->user_model->authorize(3)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||
|
||||
// Retrieve the arguments from the query string
|
||||
$arguments = $this->_retrieve();
|
||||
|
|
|
|||
|
|
@ -78,6 +78,8 @@ class Contest extends CI_Controller {
|
|||
|
||||
// Load database items
|
||||
$this->load->model('contests');
|
||||
$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'); }
|
||||
$data['templates'] = $this->contests->list_templates();
|
||||
|
||||
$this->load->helper(array('form', 'url'));
|
||||
|
|
@ -104,6 +106,8 @@ class Contest extends CI_Controller {
|
|||
*/
|
||||
public function add_template() {
|
||||
|
||||
$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'); }
|
||||
$this->load->helper(array('form', 'url'));
|
||||
$this->load->library('form_validation');
|
||||
|
||||
|
|
@ -120,4 +124,4 @@ class Contest extends CI_Controller {
|
|||
redirect('contest');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ class QSO extends CI_Controller {
|
|||
public function index()
|
||||
{
|
||||
$this->load->model('logbook_model');
|
||||
$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'); }
|
||||
|
||||
$data['notice'] = false;
|
||||
|
||||
|
|
@ -58,6 +60,8 @@ class QSO extends CI_Controller {
|
|||
function edit() {
|
||||
|
||||
$this->load->model('logbook_model');
|
||||
$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'); }
|
||||
$query = $this->logbook_model->qso_info($this->uri->segment(3));
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
|
@ -82,4 +86,4 @@ class QSO extends CI_Controller {
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class User extends CI_Controller {
|
|||
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'); }
|
||||
|
||||
$data['results'] = $this->user_model->users();
|
||||
|
||||
|
|
@ -16,6 +17,7 @@ class User extends CI_Controller {
|
|||
|
||||
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'); }
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
||||
|
|
@ -41,24 +43,36 @@ class User extends CI_Controller {
|
|||
}
|
||||
else
|
||||
{
|
||||
if($this->user_model->add($this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'))) {
|
||||
$this->session->set_flashdata('notice', 'User '.$this->input->post('user_name').' added');
|
||||
redirect('user');
|
||||
} else {
|
||||
$this->load->view('layout/header');
|
||||
$this->session->set_flashdata('notice', 'Problem adding user');
|
||||
$data['user_name'] = $this->input->post('user_name');
|
||||
$data['user_email'] = $this->input->post('user_email');
|
||||
$data['user_password'] = $this->input->post('user_password');
|
||||
$data['user_type'] = $this->input->post('user_type');
|
||||
$this->load->view('user/add', $data);
|
||||
$this->load->view('layout/footer');
|
||||
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'))) {
|
||||
// Check for errors
|
||||
case EUSERNAMEEXISTS:
|
||||
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
|
||||
break;
|
||||
case EEMAILEXISTS:
|
||||
$data['email_error'] = 'E-mail address <b>'.$this->input->post('user_email').'</b> already in use!';
|
||||
break;
|
||||
case EPASSWORDINVALID:
|
||||
$data['password_error'] = 'Invalid password!';
|
||||
break;
|
||||
// All okay, return to user screen
|
||||
case OK:
|
||||
$this->session->set_flashdata('notice', 'User '.$this->input->post('user_name').' added');
|
||||
redirect('user');
|
||||
return;
|
||||
}
|
||||
$this->load->view('layout/header');
|
||||
$data['user_name'] = $this->input->post('user_name');
|
||||
$data['user_email'] = $this->input->post('user_email');
|
||||
$data['user_password'] = $this->input->post('user_password');
|
||||
$data['user_type'] = $this->input->post('user_type');
|
||||
$this->load->view('user/add', $data);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
function edit() {
|
||||
$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'); }
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
|
@ -72,14 +86,73 @@ class User extends CI_Controller {
|
|||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
$this->load->view('layout/header');
|
||||
if($this->input->post('user_name'))
|
||||
{
|
||||
$data['user_name'] = $this->input->post('user_name');
|
||||
$data['user_email'] = $this->input->post('user_email');
|
||||
$data['user_password'] = $this->input->post('user_password');
|
||||
$data['user_type'] = $this->input->post('user_type');
|
||||
}
|
||||
$this->load->view('user/edit', $data);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->user_model->edit();
|
||||
$this->session->set_flashdata('notice', 'User updated');
|
||||
redirect('user');
|
||||
unset($data);
|
||||
switch($this->user_model->edit($this->input->post('id'), $this->input->post('user_name'), $this->input->post('user_password'), $this->input->post('user_email'), $this->input->post('user_type'))) {
|
||||
// Check for errors
|
||||
case EUSERNAMEEXISTS:
|
||||
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
|
||||
break;
|
||||
case EEMAILEXISTS:
|
||||
$data['email_error'] = 'E-mail address <b>'.$this->input->post('user_email').'</b> already in use!';
|
||||
break;
|
||||
case EPASSWORDINVALID:
|
||||
$data['password_error'] = 'Invalid password!';
|
||||
break;
|
||||
// All okay, return to user screen
|
||||
case OK:
|
||||
$this->session->set_flashdata('notice', 'User '.$this->input->post('user_name').' edited');
|
||||
redirect('user');
|
||||
return;
|
||||
}
|
||||
$this->load->view('layout/header');
|
||||
$data['user_name'] = $this->input->post('user_name');
|
||||
$data['user_email'] = $this->input->post('user_email');
|
||||
$data['user_password'] = $this->input->post('user_password');
|
||||
$data['user_type'] = $this->input->post('user_type');
|
||||
$this->load->view('user/edit', $data);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
}
|
||||
|
||||
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'); }
|
||||
$query = $this->user_model->get_by_id($this->uri->segment(3));
|
||||
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->form_validation->set_rules('id', 'user_id', 'required');
|
||||
|
||||
$data = $query->row();
|
||||
|
||||
if ($this->form_validation->run() == FALSE)
|
||||
{
|
||||
$this->load->view('layout/header');
|
||||
$this->load->view('user/delete', $data);
|
||||
$this->load->view('layout/footer');
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->user_model->delete($data->user_id))
|
||||
{
|
||||
$this->session->set_flashdata('notice', 'User deleted');
|
||||
redirect('user');
|
||||
} else {
|
||||
$this->session->set_flashdata('notice', '<b>Database error:</b> Could not delete user!');
|
||||
redirect('user');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,13 +196,4 @@ class User extends CI_Controller {
|
|||
$this->session->set_flashdata('notice', 'User '.$user_name.' logged out.');
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
/*
|
||||
function delete($id) {
|
||||
$this->load->model('note');
|
||||
$this->note->delete($id);
|
||||
|
||||
redirect('notes');
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
正在加载…
在新工单中引用