Improve user management
This commit is contained in:
@@ -30,11 +30,11 @@ require_once APPPATH . 'core/Admin_Controller.php';
|
|||||||
class Users extends Admin_Controller {
|
class Users extends Admin_Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Calls the parent constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->load->model('user');
|
$this->load->model('group');
|
||||||
$this->load->library('form_validation');
|
$this->load->library('form_validation');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,8 +42,7 @@ class Users extends Admin_Controller {
|
|||||||
* Shows a list of all users.
|
* Shows a list of all users.
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$data['users'] = $this->user->getAll();
|
$this->load->view('admin/users/list', array('users' => $this->user->getAll()));
|
||||||
$this->load->view('admin/users/list', $data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -57,16 +56,25 @@ class Users extends Admin_Controller {
|
|||||||
'firstname' => $this->input->post('firstname'),
|
'firstname' => $this->input->post('firstname'),
|
||||||
'lastname' => $this->input->post('lastname'),
|
'lastname' => $this->input->post('lastname'),
|
||||||
'institution' => $this->input->post('institution'),
|
'institution' => $this->input->post('institution'),
|
||||||
'phone' => $this->input->post('phone')
|
'phone' => $this->input->post('phone'),
|
||||||
|
'group_id' => $this->input->post('group_id'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->user->register($username, $this->input->post('password'), $this->input->post('email'), $data)) {
|
if ($this->user->register($username, $this->input->post('password'), $this->input->post('email'), $data)) {
|
||||||
$this->messages->add(sprintf(_("The user '%s' has been created successfully"), $username), 'success');
|
|
||||||
redirect('admin/users', 303);
|
redirect('admin/users', 303);
|
||||||
|
} else {
|
||||||
|
$this->messages->add(_("Something went wrong with the action you performed."), 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->load->view('admin/users/create');
|
$data = array(); // empty data array
|
||||||
|
$data['groups'] = $this->group->getAll();
|
||||||
|
|
||||||
|
// get default group
|
||||||
|
$this->load->config('auth');
|
||||||
|
$data['default'] = $this->group->getByName($this->config->item('default_group', 'auth'));
|
||||||
|
|
||||||
|
$this->load->view('admin/users/create', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,16 +95,21 @@ class Users extends Admin_Controller {
|
|||||||
'firstname' => $this->input->post('firstname'),
|
'firstname' => $this->input->post('firstname'),
|
||||||
'lastname' => $this->input->post('lastname'),
|
'lastname' => $this->input->post('lastname'),
|
||||||
'institution' => $this->input->post('institution'),
|
'institution' => $this->input->post('institution'),
|
||||||
'phone' => $this->input->post('phone')
|
'phone' => $this->input->post('phone'),
|
||||||
|
'group_id' => $this->input->post('group_id'),
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($this->user->update($user['id'], $data)) {
|
if ($this->user->update($user['id'], $data)) {
|
||||||
$this->messages->add(sprintf(_("The user '%s' has been updated successfully"), $user['username']), 'success');
|
$this->messages->add(sprintf(_("The user "%s" has been updated successfully."), $user['username']), 'success');
|
||||||
|
}
|
||||||
redirect('admin/users', 303);
|
redirect('admin/users', 303);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->load->view('admin/users/edit', array('user' => $user));
|
$data = array(); // empty data array
|
||||||
|
$data['user'] = $user;
|
||||||
|
$data['groups'] = $this->group->getAll();
|
||||||
|
|
||||||
|
$this->load->view('admin/users/edit', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -111,7 +124,6 @@ class Users extends Admin_Controller {
|
|||||||
show_404();
|
show_404();
|
||||||
} else {
|
} else {
|
||||||
$this->user->delete($user['id']);
|
$this->user->delete($user['id']);
|
||||||
$this->messages->add(_("The selected user has been deleted successfully"), 'success');
|
|
||||||
redirect('admin/users', 303);
|
redirect('admin/users', 303);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,8 +40,12 @@ class Group extends CI_Model {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function getAll() {
|
||||||
return $this->db->get('groups')->result_array();
|
$groups = array();
|
||||||
|
foreach ($this->db->get('groups')->result_array() as $group) {
|
||||||
|
$groups[$group['id']] = $group['description'];
|
||||||
|
}
|
||||||
|
return $groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h2><?=_('Create new user');?></h2>
|
<h2><?=anchor('admin/users', _('Users'));?> » <?=_('Create user');?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@@ -11,52 +11,52 @@
|
|||||||
<h3><?=_('Required information');?></h3>
|
<h3><?=_('Required information');?></h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Username'), 'username');?>
|
<?=form_label(_('Username'), 'username');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="username" id="username" class="short text" value="<?=set_value('username');?>" />
|
<input type="text" name="username" id="username" class="short text" value="<?=set_value('username');?>" />
|
||||||
<?=form_error('username')?>
|
<?=form_error('username');?>
|
||||||
</div>
|
</div>
|
||||||
<label class="note"><?=_('Must be between 4 and 20 characters long');?></label>
|
<label class="note"><?=_('Must be between 4 and 20 characters long');?></label>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Email address'), 'email');?>
|
<?=form_label(_('Email address'), 'email');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email');?>" />
|
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email');?>" />
|
||||||
<?=form_error('email')?>
|
<?=form_error('email');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Password'), 'password');?>
|
<?=form_label(_('Password'), 'password');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="password" name="password" id="password" class="short text" />
|
<input type="password" name="password" id="password" class="short text" />
|
||||||
<?=form_error('password')?>
|
<?=form_error('password');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Confirm password'), 'password_confirm');?>
|
<?=form_label(_('Confirm password'), 'password_confirm');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="password" name="password_confirm" id="password_confirm" class="short text" />
|
<input type="password" name="password_confirm" id="password_confirm" class="short text" />
|
||||||
<?=form_error('password_confirm')?>
|
<?=form_error('password_confirm');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('First name'), 'firstname');?>
|
<?=form_label(_('First name'), 'firstname');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname');?>" />
|
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname');?>" />
|
||||||
<?=form_error('firstname')?>
|
<?=form_error('firstname');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Last name'), 'lastname');?>
|
<?=form_label(_('Last name'), 'lastname');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname');?>" />
|
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname');?>" />
|
||||||
<?=form_error('lastname')?>
|
<?=form_error('lastname');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Group'), 'group_id');?> <span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<?=form_dropdown('group_id', $groups, $default['id'], 'id="group_id" class="drop"');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@@ -66,20 +66,21 @@
|
|||||||
<?=form_label(_('Institution'), 'institution');?>
|
<?=form_label(_('Institution'), 'institution');?>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution');?>" />
|
<input type="text" name="institution" id="institution" class="medium text" value="<?=set_value('institution');?>" />
|
||||||
<?=form_error('institution')?>
|
<?=form_error('institution');?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Phone number'), 'phone');?>
|
<?=form_label(_('Phone number'), 'phone');?>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone');?>" />
|
<input type="text" name="phone" id="phone" class="short text" value="<?=set_value('phone');?>" />
|
||||||
<?=form_error('phone')?>
|
<?=form_error('phone');?>
|
||||||
</div>
|
</div>
|
||||||
<label class="note"><?=('Example');?>: +49 123 456789</label>
|
<label class="note"><?=('Example');?>: +49 123 456789</label>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();"><?=_('Save');?></a>
|
<a href="javascript:void(0);" onclick="$('form[name=createUser]').submit();" class="button save"><?=_('Save');?></a>
|
||||||
|
<a href="<?=site_url('admin/users');?>" class="button cancel"><?=_('Cancel');?></a>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -3,37 +3,40 @@
|
|||||||
<div id="content">
|
<div id="content">
|
||||||
|
|
||||||
<div class="title">
|
<div class="title">
|
||||||
<h2><?php printf(_("Edit user '%s'"), $user['username']);?></h2>
|
<h2><?=anchor('admin/users', _('Users'));?> » <?=sprintf(_('Edit user "%s"'), $user['username']);?></h2>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<form name="createUser" method="post" action="<?=site_url('admin/users/edit/' . $user['id'])?>">
|
<form name="editUser" method="post" action="<?=site_url('admin/users/edit/' . $user['id'])?>">
|
||||||
<h3><?=_('Required information');?></h3>
|
<h3><?=_('Required information');?></h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Email address'), 'email');?>
|
<?=form_label(_('Email address'), 'email');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email', $user['email']);?>" />
|
<input type="text" name="email" id="email" class="medium text" value="<?=set_value('email', $user['email']);?>" />
|
||||||
<?=form_error('email')?>
|
<?=form_error('email')?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('First name'), 'firstname');?>
|
<?=form_label(_('First name'), 'firstname');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname', $user['firstname']);?>" />
|
<input type="text" name="firstname" id="firstname" class="short text" value="<?=set_value('firstname', $user['firstname']);?>" />
|
||||||
<?=form_error('firstname')?>
|
<?=form_error('firstname')?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<?=form_label(_('Last name'), 'lastname');?>
|
<?=form_label(_('Last name'), 'lastname');?> <span class="req">*</span>
|
||||||
<span class="req">*</span>
|
|
||||||
<div>
|
<div>
|
||||||
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname', $user['lastname']);?>" />
|
<input type="text" name="lastname" id="lastname" class="short text" value="<?=set_value('lastname', $user['lastname']);?>" />
|
||||||
<?=form_error('lastname')?>
|
<?=form_error('lastname')?>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Group'), 'group_id');?> <span class="req">*</span>
|
||||||
|
<div>
|
||||||
|
<?=form_dropdown('group_id', $groups, $user['group_id'], 'id="group_id" class="drop"');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<h3><?=_('Optional information');?></h3>
|
<h3><?=_('Optional information');?></h3>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -54,8 +57,8 @@
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>
|
<p>
|
||||||
<a class="button save" href="javascript:void(0);" onclick="$('form[name=createUser]').submit();"><?=_('Save');?></a>
|
<a href="javascript:void(0);" onclick="$('form[name=editUser]').submit();" class="button save"><?=_('Save');?></a>
|
||||||
<a class="button cancel" href="<?=site_url('admin/users');?>"><?=_('Cancel');?></a>
|
<a href="<?=site_url('admin/users');?>" class="button cancel"><?=_('Cancel');?></a>
|
||||||
</p>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,16 +22,22 @@
|
|||||||
?>
|
?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?=$user['username'];?></td>
|
<td><?=$user['username'];?></td>
|
||||||
<td><?=$user['firstname'];?> <?=$user['lastname'];?></td>
|
<td><?=$user['firstname'] . ' ' . $user['lastname'];?></td>
|
||||||
<td><?=anchor('admin/users/edit/' . $user['id'], _('Edit'));?> | <a href="javascript:deleteConfirm('<?=site_url('admin/users/delete/' . $user['id']);?>');"><?=_('Delete');?></a></td>
|
<td>
|
||||||
|
<?=anchor('admin/users/edit/' . $user['id'], _('Edit'));?> |
|
||||||
|
<a href="javascript:deleteConfirm('<?=site_url('admin/users/delete/' . $user['id']);?>');"><?=_('Delete');?></a>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
?>
|
?>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<h3><?=_('Actions');?></h3>
|
||||||
<p><a class="button add" href="<?=site_url('admin/users/create')?>"><?=_('Create new user')?></a>
|
<p>
|
||||||
|
<a href="<?=site_url('admin/users/create')?>" class="button user_add"><?=_('Create user');?></a>
|
||||||
|
<a class="button disabled search"><?=_('Search user');?></a>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -585,6 +585,11 @@ a.project_rename {
|
|||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.user_add {
|
||||||
|
background: url(../images/icons/user--plus.png) 10px center no-repeat #f3f3f3;
|
||||||
|
padding-left: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
a.results {
|
a.results {
|
||||||
background: url(../images/icons/blue-folder-open-document-text.png) 10px center no-repeat #f3f3f3;
|
background: url(../images/icons/blue-folder-open-document-text.png) 10px center no-repeat #f3f3f3;
|
||||||
padding-left: 30px;
|
padding-left: 30px;
|
||||||
|
|||||||
Reference in New Issue
Block a user