Controller work for user functions

这个提交包含在:
Andy Smith 2011-08-19 17:12:13 +01:00
父节点 28ee178dd1
当前提交 5a003c5665
共有 4 个文件被更改,包括 100 次插入26 次删除

查看文件

@ -71,6 +71,8 @@ class API extends CI_Controller {
// Load the API and Logbook models // Load the API and Logbook models
$this->load->model('api_model'); $this->load->model('api_model');
$this->load->model('logbook_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 // Retrieve the arguments from the query string
$arguments = $this->_retrieve(); $arguments = $this->_retrieve();

查看文件

@ -78,6 +78,8 @@ class Contest extends CI_Controller {
// Load database items // Load database items
$this->load->model('contests'); $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(); $data['templates'] = $this->contests->list_templates();
$this->load->helper(array('form', 'url')); $this->load->helper(array('form', 'url'));
@ -104,6 +106,8 @@ class Contest extends CI_Controller {
*/ */
public function add_template() { 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->helper(array('form', 'url'));
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -120,4 +124,4 @@ class Contest extends CI_Controller {
redirect('contest'); redirect('contest');
} }
} }
} }

查看文件

@ -13,6 +13,8 @@ class QSO extends CI_Controller {
public function index() public function index()
{ {
$this->load->model('logbook_model'); $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; $data['notice'] = false;
@ -58,6 +60,8 @@ class QSO extends CI_Controller {
function edit() { function edit() {
$this->load->model('logbook_model'); $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)); $query = $this->logbook_model->qso_info($this->uri->segment(3));
$this->load->library('form_validation'); $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() public function index()
{ {
$this->load->model('user_model'); $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(); $data['results'] = $this->user_model->users();
@ -16,6 +17,7 @@ class User extends CI_Controller {
function add() { function add() {
$this->load->model('user_model'); $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'); $this->load->library('form_validation');
@ -41,24 +43,36 @@ class User extends CI_Controller {
} }
else 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'))) { 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'))) {
$this->session->set_flashdata('notice', 'User '.$this->input->post('user_name').' added'); // Check for errors
redirect('user'); case EUSERNAMEEXISTS:
} else { $data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
$this->load->view('layout/header'); break;
$this->session->set_flashdata('notice', 'Problem adding user'); case EEMAILEXISTS:
$data['user_name'] = $this->input->post('user_name'); $data['email_error'] = 'E-mail address <b>'.$this->input->post('user_email').'</b> already in use!';
$data['user_email'] = $this->input->post('user_email'); break;
$data['user_password'] = $this->input->post('user_password'); case EPASSWORDINVALID:
$data['user_type'] = $this->input->post('user_type'); $data['password_error'] = 'Invalid password!';
$this->load->view('user/add', $data); break;
$this->load->view('layout/footer'); // 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() { function edit() {
$this->load->model('user_model'); $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)); $query = $this->user_model->get_by_id($this->uri->segment(3));
$this->load->library('form_validation'); $this->load->library('form_validation');
@ -72,14 +86,73 @@ class User extends CI_Controller {
if ($this->form_validation->run() == FALSE) if ($this->form_validation->run() == FALSE)
{ {
$this->load->view('layout/header'); $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('user/edit', $data);
$this->load->view('layout/footer'); $this->load->view('layout/footer');
} }
else else
{ {
$this->user_model->edit(); unset($data);
$this->session->set_flashdata('notice', 'User updated'); 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'))) {
redirect('user'); // 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.'); $this->session->set_flashdata('notice', 'User '.$user_name.' logged out.');
redirect('dashboard'); redirect('dashboard');
} }
/*
function delete($id) {
$this->load->model('note');
$this->note->delete($id);
redirect('notes');
}
*/
} }