More user changes, including profile page
这个提交包含在:
父节点
576df8be26
当前提交
74116240dd
共有 6 个文件被更改,包括 203 次插入 和 52 次删除
|
|
@ -41,6 +41,7 @@ define('EEMAILEXISTS', 'E-mail address already exists');
|
||||||
define('EUSERNAMEEXISTS', 'Username already exists');
|
define('EUSERNAMEEXISTS', 'Username already exists');
|
||||||
define('EPASSWORDINVALID', 'Invalid password');
|
define('EPASSWORDINVALID', 'Invalid password');
|
||||||
define('ENOSUCHUSER', 'No such user');
|
define('ENOSUCHUSER', 'No such user');
|
||||||
|
define('EFORBIDDEN', 'Forbidden');
|
||||||
|
|
||||||
define('OK', 'OK');
|
define('OK', 'OK');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,34 +72,81 @@ class User extends CI_Controller {
|
||||||
|
|
||||||
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'); }
|
if((!$this->user_model->authorize(99)) && ($this->session->userdata('user_id') != $this->uri->segment(3))) { $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');
|
||||||
|
|
||||||
$this->form_validation->set_rules('user_name', 'Username', '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_email', 'E-mail', 'required');
|
||||||
$this->form_validation->set_rules('user_type', 'Type', 'required');
|
if($this->session->userdata('user_type') == 99)
|
||||||
|
{
|
||||||
|
$this->form_validation->set_rules('user_type', 'Type', 'required');
|
||||||
|
}
|
||||||
|
|
||||||
$data = $query->row();
|
|
||||||
|
|
||||||
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'))
|
$q = $query->row();
|
||||||
{
|
|
||||||
|
$data['id'] = $q->user_id;
|
||||||
|
|
||||||
|
if($this->input->post('user_name')) {
|
||||||
$data['user_name'] = $this->input->post('user_name');
|
$data['user_name'] = $this->input->post('user_name');
|
||||||
$data['user_email'] = $this->input->post('user_email');
|
} else {
|
||||||
$data['user_password'] = $this->input->post('user_password');
|
$data['user_name'] = $q->user_name;
|
||||||
$data['user_type'] = $this->input->post('user_type');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_email')) {
|
||||||
|
$data['user_email'] = $this->input->post('user_email');
|
||||||
|
} else {
|
||||||
|
$data['user_email'] = $q->user_email;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_password')) {
|
||||||
|
$data['user_password'] = $this->input->post('user_password');
|
||||||
|
} else {
|
||||||
|
$data['user_password'] = $q->user_password;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_type')) {
|
||||||
|
$data['user_type'] = $this->input->post('user_type');
|
||||||
|
} else {
|
||||||
|
$data['user_type'] = $q->user_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_callsign')) {
|
||||||
|
$data['user_callsign'] = $this->input->post('user_callsign');
|
||||||
|
} else {
|
||||||
|
$data['user_callsign'] = $q->user_callsign;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_locator')) {
|
||||||
|
$data['user_locator'] = $this->input->post('user_locator');
|
||||||
|
} else {
|
||||||
|
$data['user_locator'] = $q->user_locator;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_firstname')) {
|
||||||
|
$data['user_firstname'] = $this->input->post('user_firstname');
|
||||||
|
} else {
|
||||||
|
$data['user_firstname'] = $q->user_firstname;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->input->post('user_lastname')) {
|
||||||
|
$data['user_lastname'] = $this->input->post('user_lastname');
|
||||||
|
} else {
|
||||||
|
$data['user_lastname'] = $q->user_lastname;
|
||||||
|
}
|
||||||
|
|
||||||
$this->load->view('user/edit', $data);
|
$this->load->view('user/edit', $data);
|
||||||
$this->load->view('layout/footer');
|
$this->load->view('layout/footer');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unset($data);
|
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'))) {
|
switch($this->user_model->edit($this->input->post())) {
|
||||||
// Check for errors
|
// Check for errors
|
||||||
case EUSERNAMEEXISTS:
|
case EUSERNAMEEXISTS:
|
||||||
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
|
$data['username_error'] = 'Username <b>'.$this->input->post('user_name').'</b> already in use!';
|
||||||
|
|
@ -126,6 +173,16 @@ class User extends CI_Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function profile() {
|
||||||
|
$this->load->model('user_model');
|
||||||
|
$query = $this->user_model->get_by_id($this->session->userdata('user_id'));
|
||||||
|
|
||||||
|
$this->load->view('layout/header');
|
||||||
|
$data = $query->row();
|
||||||
|
$this->load->view('user/profile', $data);
|
||||||
|
$this->load->view('layout/footer');
|
||||||
|
}
|
||||||
|
|
||||||
function delete() {
|
function delete() {
|
||||||
$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'); }
|
if(!$this->user_model->authorize(99)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
|
||||||
|
|
|
||||||
|
|
@ -104,39 +104,52 @@ class User_Model extends CI_Model {
|
||||||
|
|
||||||
// FUNCTION: bool edit()
|
// FUNCTION: bool edit()
|
||||||
// Edit a user
|
// Edit a user
|
||||||
function edit($id, $username, $password, $email, $type) {
|
function edit($fields) {
|
||||||
|
|
||||||
if($this->exists_by_id($id)) {
|
// Check user privileges
|
||||||
$data = array(
|
if(($this->session->userdata('user_type') == 99) || ($this->session->userdata('user_id') == $fields['id'])) {
|
||||||
'user_name' => $username,
|
if($this->exists_by_id($fields['id'])) {
|
||||||
'user_email' => $email,
|
$data = array(
|
||||||
'user_type' => $type
|
'user_name' => $fields['user_name'],
|
||||||
);
|
'user_email' => $fields['user_email'],
|
||||||
|
'user_callsign' => $fields['user_callsign'],
|
||||||
|
'user_locator' => $fields['user_locator'],
|
||||||
|
'user_firstname' => $fields['user_firstname'],
|
||||||
|
'user_lastname' => $fields['user_lastname']
|
||||||
|
);
|
||||||
|
|
||||||
// Check to see if username is used already
|
// Check to see if the user is allowed to change user levels
|
||||||
if($this->exists($username) && $this->get($username)->row()->user_id != $id) {
|
if($this->session->userdata('user_type') == 99) {
|
||||||
return EUSERNAMEEXISTS;
|
$data['user_type'] = $fields['user_type'];
|
||||||
}
|
|
||||||
// Check to see if email address is used already
|
|
||||||
if($this->exists_by_email($email) && $this->get_by_email($email)->row()->user_id != $id) {
|
|
||||||
return EEMAILEXISTS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash password
|
|
||||||
if($password != NULL)
|
|
||||||
{
|
|
||||||
$data['user_password'] = $this->_hash($password);
|
|
||||||
if($data['user_password'] == EPASSWORDINVALID) {
|
|
||||||
return EPASSWORDINVALID;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Update the user
|
// Check to see if username is used already
|
||||||
$this->db->where('user_id', $this->input->post('id'));
|
if($this->exists($fields['user_name']) && $this->get($fields['user_name'])->row()->user_id != $fields['id']) {
|
||||||
$this->db->update($this->config->item('auth_table'), $data);
|
return EUSERNAMEEXISTS;
|
||||||
return OK;
|
}
|
||||||
|
// Check to see if email address is used already
|
||||||
|
if($this->exists_by_email($fields['user_email']) && $this->get_by_email($fields['user_email'])->row()->user_id != $fields['id']) {
|
||||||
|
return EEMAILEXISTS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hash password
|
||||||
|
if($fields['user_password'] != NULL)
|
||||||
|
{
|
||||||
|
$data['user_password'] = $this->_hash($fields['user_password']);
|
||||||
|
if($data['user_password'] == EPASSWORDINVALID) {
|
||||||
|
return EPASSWORDINVALID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the user
|
||||||
|
$this->db->where('user_id', $fields['id']);
|
||||||
|
$this->db->update($this->config->item('auth_table'), $data);
|
||||||
|
return OK;
|
||||||
|
} else {
|
||||||
|
return ENOSUCHUSER;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return EFORBIDDEN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -150,7 +150,7 @@ margin: 10px 0;
|
||||||
<?php if($this->config->item('use_auth')) { ?>
|
<?php if($this->config->item('use_auth')) { ?>
|
||||||
<ul id="user">
|
<ul id="user">
|
||||||
<?php if($this->session->userdata('user_id')) { ?>
|
<?php if($this->session->userdata('user_id')) { ?>
|
||||||
<li><a href="<?php echo site_url('user/account');?>"><?php echo $this->session->userdata('user_name'); ?></a></li>
|
<li><a href="<?php echo site_url('user/profile');?>"><?php echo $this->session->userdata('user_name'); ?></a></li>
|
||||||
<li><a href="<?php echo site_url('user/logout');?>">Logout</a></li>
|
<li><a href="<?php echo site_url('user/logout');?>">Logout</a></li>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<li><a href="<?php echo site_url('user/login');?>">Log in</a></li>
|
<li><a href="<?php echo site_url('user/login');?>">Log in</a></li>
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,26 @@
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Level</td>
|
||||||
|
<td>
|
||||||
|
<?php if($this->session->userdata('user_type') == 99) { ?>
|
||||||
|
<select name="user_type">
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$levels = $this->config->item('auth_level');
|
||||||
|
while (list($key, $val) = each($levels)) {
|
||||||
|
?>
|
||||||
|
<option value="<?php echo $key; ?>" <?php if($user_type == $key) { echo "selected=\"selected\""; } ?>><?php echo $val; ?></option>
|
||||||
|
<?php } ?>
|
||||||
|
</select>
|
||||||
|
<?php } else {
|
||||||
|
$l = $this->config->item('auth_level');
|
||||||
|
echo $l[$user_type];
|
||||||
|
}?>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>E-mail</td>
|
<td>E-mail</td>
|
||||||
<td><input type="text" name="user_email" value="<?php if(isset($user_email)) { echo $user_email; } ?>" />
|
<td><input type="text" name="user_email" value="<?php if(isset($user_email)) { echo $user_email; } ?>" />
|
||||||
|
|
@ -27,21 +47,36 @@
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>Type</td>
|
<td>Callsign</td>
|
||||||
<td><select name="user_type">
|
<td><input type="text" name="user_callsign" value="<?php if(isset($user_callsign)) { echo $user_callsign; } ?>" />
|
||||||
<?php
|
<?php if(isset($callsign_error)) { echo "<div class=\"small error\">".$callsign_error."</div>"; } else { ?>
|
||||||
|
<?php } ?>
|
||||||
$levels = $this->config->item('auth_level');
|
|
||||||
while (list($key, $val) = each($levels)) {
|
|
||||||
?>
|
|
||||||
<option value="<?php echo $key; ?>" <?php if($user_type == $key) { echo "selected=\"selected\""; } ?>><?php echo $val; ?></option>
|
|
||||||
<?php } ?>
|
|
||||||
</select>
|
|
||||||
</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Locator</td>
|
||||||
|
<td><input type="text" name="user_locator" value="<?php if(isset($user_locator)) { echo $user_locator; } ?>" />
|
||||||
|
<?php if(isset($locator_error)) { echo "<div class=\"small error\">".$locator_error."</div>"; } else { ?>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>First name</td>
|
||||||
|
<td><input type="text" name="user_firstname" value="<?php if(isset($user_firstname)) { echo $user_firstname; } ?>" />
|
||||||
|
<?php if(isset($firstname_error)) { echo "<div class=\"small error\">".$firstname_error."</div>"; } else { ?>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Last name</td>
|
||||||
|
<td><input type="text" name="user_lastname" value="<?php if(isset($user_lastname)) { echo $user_lastname; } ?>" />
|
||||||
|
<?php if(isset($lastname_error)) { echo "<div class=\"small error\">".$lastname_error."</div>"; } else { ?>
|
||||||
|
<?php } ?>
|
||||||
|
</tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />
|
<input type="hidden" name="id" value="<?php echo $this->uri->segment(3); ?>" />
|
||||||
<div><input type="submit" value="Submit" /></div>
|
<div><input type="submit" value="Update profile" /></div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<h2><?php echo $this->session->userdata('user_name')."'s profile"; ?></h2>
|
||||||
|
<div class="wrap_content user">
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Username</td>
|
||||||
|
<td><?php if(isset($user_name)) { echo $user_name; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Level</td>
|
||||||
|
<td><?php $l = $this->config->item('auth_level'); echo $l[$user_type]; ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>E-mail</td>
|
||||||
|
<td><?php if(isset($user_email)) { echo $user_email; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Callsign</td>
|
||||||
|
<td><?php if(isset($user_callsign)) { echo $user_callsign; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Locator</td>
|
||||||
|
<td><?php if(isset($user_locator)) { echo $user_locator; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>First name</td>
|
||||||
|
<td><?php if(isset($user_firstname)) { echo $user_firstname; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td>Last name</td>
|
||||||
|
<td><?php if(isset($user_lastname)) { echo $user_lastname; } ?></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
</table>
|
||||||
|
<div><a href="<?php echo site_url('user/edit')."/".$this->session->userdata('user_id'); ?>">Edit profile</a></div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
正在加载…
在新工单中引用