More user changes. 'user/add' now implemented.

pull/106/merge
Andy Smith 2011-08-18 02:27:53 +01:00
rodzic 7c76e0b37f
commit c2a7e45ca5
6 zmienionych plików z 81 dodań i 27 usunięć

Wyświetl plik

@ -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";
/*
|--------------------------------------------------------------------------

Wyświetl plik

@ -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');
}
}
function view($id) {
$this->load->model('note');
$data['note'] = $this->note->view($id);
// Display
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->load->view('notes/view',$data);
$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 edit() {
$this->load->model('user_model');

Wyświetl plik

@ -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;

Wyświetl plik

@ -0,0 +1,41 @@
<h2>Add user</h2>
<div class="wrap_content user">
<?php echo validation_errors(); ?>
<form method="post" action="<?php echo site_url('user/add'); ?>" name="users">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="user_name" value="<?php if(isset($user_name)) { echo $user_name; } ?>" /></td>
</tr>
<tr>
<td>E-mail</td>
<td><input type="text" name="user_email" value="<?php if(isset($user_email)) { echo $user_email; } ?>" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="user_password" value="<?php if(isset($user_password)) { echo $user_password; } ?>" /></td>
</tr>
<tr>
<td>Type</td>
<td><select name="user_type">
<?php
$levels = $this->config->item('auth_level');
while (list($key, $val) = each($levels)) {
?>
<option value="<?php echo $key; ?>" <?php if(isset($user_type)) { if($user_type == $key) { echo "selected=\"selected\""; } } ?>><?php echo $val; ?></option>
<?php } ?>
</select>
</td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />
<div><input type="submit" value="Submit" /></div>
</form>
</div>

Wyświetl plik

@ -16,7 +16,7 @@
<tr>
<td>Password</td>
<td><input type="text" name="user_password" /><br><div class="small">Leave blank to keep existing password</div></td>
<td><input type="password" name="user_password" /><br><div class="small">Leave blank to keep existing password</div></td>
</tr>
<tr>

Wyświetl plik

@ -50,4 +50,5 @@
</tr>
<?php $i++; } ?>
</table>
<div class="controls"><a href="<?php echo site_url('user/add'); ?>">Add user</a></div>
</div>