From c2a7e45ca5070dab81fc97d03fa5c8540e479c71 Mon Sep 17 00:00:00 2001 From: Andy Smith Date: Thu, 18 Aug 2011 02:27:53 +0100 Subject: [PATCH] More user changes. 'user/add' now implemented. --- application/config/config.php | 6 ++++ application/controllers/user.php | 54 +++++++++++++++++-------------- application/models/user_model.php | 4 +-- application/views/user/add.php | 41 +++++++++++++++++++++++ application/views/user/edit.php | 2 +- application/views/user/main.php | 1 + 6 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 application/views/user/add.php diff --git a/application/config/config.php b/application/config/config.php index 5cb12a6c..89ddc4aa 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -15,6 +15,12 @@ $config['auth_table'] = "users"; // Minimum user level required // 0 = anonymous, 1 = viewer, 2 = editor, 3 = api user, 99 = owner $config['auth_mode'] = "0"; +// User levels +$config['auth_level'][0] = "Anonymous"; +$config['auth_level'][1] = "Viewer"; +$config['auth_level'][2] = "Editor"; +$config['auth_level'][3] = "API User"; +$config['auth_level'][99] = "Administrator"; /* |-------------------------------------------------------------------------- diff --git a/application/controllers/user.php b/application/controllers/user.php index 7b73dd88..b9100466 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -14,42 +14,48 @@ class User extends CI_Controller { $this->load->view('layout/footer'); } - /* function add() { - - $this->load->model('note'); - + $this->load->model('user_model'); + $this->load->library('form_validation'); - $this->form_validation->set_rules('title', 'Note Title', 'required'); - $this->form_validation->set_rules('content', 'Content', 'required'); - + $this->form_validation->set_rules('user_name', 'Username', 'required'); + $this->form_validation->set_rules('user_email', 'E-mail', 'required'); + $this->form_validation->set_rules('user_password', 'Password', 'required'); + $this->form_validation->set_rules('user_type', 'Type', 'required'); if ($this->form_validation->run() == FALSE) { $this->load->view('layout/header'); - $this->load->view('notes/add'); + 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/add', $data); + } else { + $this->load->view('user/add'); + } $this->load->view('layout/footer'); } else - { - $this->note->add(); - - redirect('notes'); + { + 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'); + } } } - - function view($id) { - $this->load->model('note'); - - $data['note'] = $this->note->view($id); - - // Display - $this->load->view('layout/header'); - $this->load->view('notes/view',$data); - $this->load->view('layout/footer'); - } - */ function edit() { $this->load->model('user_model'); diff --git a/application/models/user_model.php b/application/models/user_model.php index f6230e73..ccc3d752 100644 --- a/application/models/user_model.php +++ b/application/models/user_model.php @@ -25,7 +25,7 @@ class User_Model extends CI_Model { } function exists($username) { - if($this->get($username)->results()->num_rows == 0) { + if($this->get($username)->num_rows == 0) { return 0; } else { return 1; @@ -41,7 +41,7 @@ class User_Model extends CI_Model { 'user_type' => $type ); - $this->db->insert($this->config->item('auth_table')); + $this->db->insert($this->config->item('auth_table'), $data); return 1; } else { return 0; diff --git a/application/views/user/add.php b/application/views/user/add.php new file mode 100644 index 00000000..8a21f51e --- /dev/null +++ b/application/views/user/add.php @@ -0,0 +1,41 @@ +

Add user

+
+ + +
+ + + + + + + + + + + + + + + + + + + + +
Username
E-mail
Password
Type +
+ +
+ +
+ +
diff --git a/application/views/user/edit.php b/application/views/user/edit.php index 6a7a8323..466bbb8f 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -16,7 +16,7 @@ Password -
Leave blank to keep existing password
+
Leave blank to keep existing password
diff --git a/application/views/user/main.php b/application/views/user/main.php index 5d40ce6d..66a4c0dd 100644 --- a/application/views/user/main.php +++ b/application/views/user/main.php @@ -50,4 +50,5 @@ +
Add user