Started user management interface. Need PHP backend.

This commit is contained in:
Phyks 2013-08-10 23:58:40 +02:00
parent 653f50c33d
commit d97292ada3
7 changed files with 122 additions and 7 deletions

8
TODO
View File

@ -1,8 +1,16 @@
* i18n
* Vérification des variables dans les classes + throw exception
* tokens + ban system
* remember me
* Display names
install.php :
=============
* Link beside password field to toggle visible / not visible
* TRUNCATE before CREATE TABLE in install.php
index.php :
===========
* Delete user (+ check if not you)
* Edit user
* Create user

View File

@ -70,7 +70,7 @@ class User extends Storage {
return serialize(array('id'=>$this->id, 'login'=>$this->login, 'password'=>$this->password, 'admin'=>$this->admin));
}
public function sessionRestore($data, $serialized) {
public function sessionRestore($data, $serialized = false) {
if($serialized)
$user_data = unserialize($serialized_data);
else
@ -81,4 +81,31 @@ class User extends Storage {
$this->setPassword($user_data['password']);
$this->setAdmin($user_data['admin']);
}
public function load_users() {
$return = array();
$users = $this->load();
foreach($users as $user) {
$return[0] = new User();
$return[0]->sessionRestore($user);
}
return $return;
}
public function load_user($fields = NULL) {
$fetch = $this->load($fields);
if(count($fetch) > 0) {
$this->setId($fetch[0]['id']);
$this->setLogin($fetch[0]['login']);
$this->setPassword($fetch[0]['password']);
$this->setAdmin($fetch[0]['admin']);
return true;
}
else {
return false;
}
}
}

View File

@ -68,11 +68,42 @@
$tpl->assign('error', 'The content of the two password fields doesn\'t match.');
}
}
$tpl->assign('view', 'password');
$tpl->draw('edit_users');
break;
case 'edit_users':
case 'add_user':
if(!$current_user['admin']) {
header('location: index.php');
}
if(!empty($_GET['user_id']) || $_GET['do'] == 'add_user') {
if(!empty($_GET['user_id'])) {
$user_id = (int) $_GET['user_id'];
$user = new User();
$user->load_user(array('id'=>$user_id));
$tpl->assign('user_data', $user);
}
$tpl->assign('user_id', (!empty($user_id) ? $user_id : -1));
$tpl->assign('view', 'edit_user');
}
else {
$users_list = new User();
$users_list = $users_list->load_users();
$tpl->assign('users', $users_list);
$tpl->assign('view', 'list_users');
}
$tpl->draw('edit_users');
break;
case 'delete_user':
break;
default:
$tpl->assign('users', array(0=>array("name"=>"truc")));
$users_list = new User();
$users_list = $users_list->load_users();
$tpl->assign('users', $users_list);
$tpl->assign('bill', array(0=>array()));
$tpl->draw('index');
break;

View File

@ -9,14 +9,14 @@
<th>Owes\To</th>
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
<th><?php echo $value1["name"];?></th>
<th><?php echo $value1->getLogin();?></th>
<?php } ?>
</tr>
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
<tr>
<th><?php echo $value1["name"];?></th>
<th><?php echo $value1->getLogin();?></th>
</tr>
<?php } ?>

View File

@ -72,11 +72,15 @@ input[type=submit] {
text-align: center
}
#edit_password_form {
#edit_password_form, #edit_user_form {
width: 50%;
margin-left: 15%;
}
#edit_user_admin_rights {
text-align: center;
}
#install {
margin: 0;
}

View File

@ -4,9 +4,54 @@
<p class="error">{$error}</p>
{/if}
{if condition="$view == 'list_users'"}
<h2>List of users</h2>
<p>You can also <a href="?do=add_user">add a user</a>.</p>
<table>
<tr>
<th>Id</th>
<th>Login</th>
<th>Is admin ?</th>
<th>Edit</th>
<th>Delete</th>
</tr>
{loop="users"}
<tr>
<td>{$value->getId()}</td>
<td>{$value->getLogin()}</td>
<td>{$value->getAdmin() ? "Yes" : "No"}</td>
<td><a href="index.php?do=edit_users&user_id={$value->getId()}">Edit</a></td>
<td><a href="index.php?do=delete_user&user_id={$value->getId()}">Delete</a></td>
</tr>
{/loop}
</table>
{elseif condition="$view == 'edit_user'"}
<h2>Edit a user</h2>
<form method="post" action="index.php" id="edit_user_form">
<p>
<label for="login" class="label-block">Login : </label><input type="text" name="login" id="login" {$user_id != -1 ? 'value="'.$user_data->getLogin().'"' : ''}/>
</p>
<p>
<label for="password" class="label-block">Password : </label><input type="password" name="password" id="password"/>
{if condition="$user_id != -1"}
<br/><em>Note :</em> Leave blank this field if you don't want to edit password.
{/if}
</p>
<p id="edit_user_admin_rights">
Give admin rights to this user ?<br/>
<input type="radio" id="admin_yes" name="admin" {if condition="$user_id != -1 && $user_data->getAdmin()"}checked{/if}/><label for="admin_yes">Yes</label><br/>
<input type="radio" id="admin_no" id="admin" {if condition="$user_id == -1 || !$user_data->getAdmin()"}checked{/if}/><label for="admin_no">No</label>
</p>
<p class="center">
<input type="submit" value="{$user_id != -1 ? 'Edit' : 'Add'}"/>
</p>
</form>
{elseif condition="$view == 'password'"}
<h2>Edit your password</h2>
<form method="post" action="index.php?do=password" id="edit_password_form">
<p><label for="password" class="label-block">New password : </label><input type="password" id="password" name="password"/></p>
<p><label for="password_confirm" class="label-block">Confirm new password : </label><input type="password" id="password_confirm" name="password_confirm"/></p>
<p class="center"><input type="submit" value="Update"/></p>
</form>
{/if}

View File

@ -7,12 +7,12 @@
<tr>
<th>Owes\To</th>
{loop="users"}
<th>{$value.name}</th>
<th>{$value->getLogin()}</th>
{/loop}
</tr>
{loop="users"}
<tr>
<th>{$value.name}</th>
<th>{$value->getLogin()}</th>
</tr>
{/loop}
</table>