Added a display name field to have a different login and displayed name for users

This commit is contained in:
Phyks 2013-08-13 17:58:14 +02:00
parent b927394620
commit 28298c381c
12 changed files with 30 additions and 10 deletions

1
TODO
View File

@ -2,7 +2,6 @@
* Vérification des variables dans les classes + throw exception
* tokens + ban system
* remember me
* Display names
* htmlspecialchars => on users objects
* Associate a guest with someone

View File

@ -3,11 +3,12 @@ require_once('data/config.php');
require_once('Storage.class.php');
class User extends Storage {
protected $id, $login, $password, $admin;
protected $id, $login, $display_name, $password, $admin;
protected $TABLE_NAME = "Users";
protected $fields = array(
'id'=>'key',
'login'=>'string',
'display_name'=>'string',
'password'=>'password',
'admin'=>'bool'
);
@ -20,6 +21,10 @@ class User extends Storage {
return $this->login;
}
public function getDisplayName() {
return $this->display_name;
}
public function getId() {
return $this->id;
}
@ -36,6 +41,10 @@ class User extends Storage {
$this->login = $login;
}
public function setDisplayName($display_name) {
$this->display_name = $display_name;
}
public function setPassword($password) {
$this->password = $password;
}
@ -56,6 +65,7 @@ class User extends Storage {
$user_data = $this->load(array('login'=>$this->login));
if(count($user_data) == 1) {
$this->setId($user_data[0]['id']);
$this->setDisplayName($user_data[0]['admin']);
$this->setAdmin($user_data[0]['admin']);
$this->setPassword($user_data[0]['password']);
@ -67,7 +77,7 @@ class User extends Storage {
}
public function sessionStore() {
return serialize(array('id'=>$this->id, 'login'=>$this->login, 'password'=>$this->password, 'admin'=>$this->admin));
return serialize(array('id'=>$this->id, 'login'=>$this->login, 'display_name'=>$this->display_name, 'password'=>$this->password, 'admin'=>$this->admin));
}
public function sessionRestore($data, $serialized = false) {
@ -78,6 +88,7 @@ class User extends Storage {
$this->setId($user_data['id']);
$this->setLogin($user_data['login']);
$this->setDisplayName($user_data['display_name']);
$this->setPassword($user_data['password']);
$this->setAdmin($user_data['admin']);
}
@ -99,6 +110,7 @@ class User extends Storage {
if(count($fetch) > 0) {
$this->setId($fetch[0]['id']);
$this->setLogin($fetch[0]['login']);
$this->setDisplayName($fetch[0]['display_name']);
$this->setPassword($fetch[0]['password']);
$this->setAdmin($fetch[0]['admin']);

View File

@ -91,12 +91,13 @@
header('location: index.php');
}
if(!empty($_POST['login']) && (!empty($_POST['password']) || !empty($_POST['user_id'])) && isset($_POST['admin'])) {
if(!empty($_POST['login']) && !empty($_POST['display_name']) && (!empty($_POST['password']) || !empty($_POST['user_id'])) && isset($_POST['admin'])) {
$user = new User();
if(!empty($_POST['user_id'])) {
$user->setId($_POST['user_id']);
}
$user->setLogin($_POST['login']);
$user->setDisplayName($_POST['login']);
if(!empty($_POST['password'])) {
$user->setPassword($user->encrypt($_POST['password']));
}
@ -125,6 +126,7 @@
$tpl->assign('view', 'list_users');
}
$tpl->assign('login_post', (!empty($_POST['login']) ? htmlspecialchars($_POST['login']) : ''));
$tpl->assign('display_name_post', (!empty($_POST['display_name']) ? htmlspecialchars($_POST['display_name']) : ''));
$tpl->assign('admin_post', (isset($_POST['admin']) ? (int) $_POST['admin'] : -1));
$tpl->draw('edit_users');
break;

View File

@ -23,7 +23,7 @@
$db = new PDO('mysql:host='.$mysql_host.';dbname='.$mysql_db, $mysql_login, $mysql_password);
//Create table "Users"
$dump = $db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, login VARCHAR(255), password VARCHAR(130), admin TINYINT(1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
$dump = $db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, login VARCHAR(255), display_name VARCHAR(255), password VARCHAR(130), admin TINYINT(1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
//Create table "Invoices" - TODO
//Create table "Payback" - TODO
@ -58,6 +58,7 @@
require_once('inc/User.class.php');
$admin = new User();
$admin->setLogin($_POST['admin_login']);
$admin->setDisplayName($_POST['admin_display_name']);
$admin->setPassword($admin->encrypt($_POST['admin_password']));
$admin->setAdmin(true);
$admin->save();
@ -116,6 +117,7 @@
<fieldset>
<legend>Administrator</legend>
<p><label for="admin_login">Username of the admin : </label><input type="text" name="admin_login" id="admin_login" <?php echo (!empty($_POST['admin_login'])) ? 'value="'.htmlspecialchars($_POST['admin_login']).'"' : '';?>/></p>
<p><label for="admin_display_name">Displayed name for admin user : </label><input type="text" name="admin_display_name" id="admin_display_name" <?php echo (!empty($_POST['admin_display_name']) ? 'value="'.htmlspecialchars($_POST['admin_display_name']).'"' : '');?>/></p>
<p><label for="admin_password">Password for the admin : </label><input type="password" name="admin_password" id="admin_password"/></p>
</fieldset>
<p class="center"><input <?php echo (!empty($block_form)) ? 'disabled ' : '';?>type="submit" value="Install"></p>

View File

View File

0
tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php Normal file → Executable file
View File

0
tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php Normal file → Executable file
View File

4
tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php Normal file → Executable file
View File

@ -15,14 +15,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->getLogin();?></th>
<th><?php echo $value1->getDisplayName();?></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->getLogin();?></th>
<th><?php echo $value1->getDisplayName();?></th>
</tr>
<?php } ?>

0
tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php Normal file → Executable file
View File

View File

@ -11,6 +11,7 @@
<tr>
<th>Id</th>
<th>Login</th>
<th>Display Name</th>
<th>Is admin ?</th>
<th>Edit</th>
<th>Delete</th>
@ -19,6 +20,7 @@
<tr>
<td>{$value->getId()}</td>
<td>{$value->getLogin()}</td>
<td>{$value->getDisplayName()}</td>
<td>{$value->getAdmin() ? "Yes" : "No"}</td>
<td><a href="index.php?do=edit_users&user_id={$value->getId()}">Edit</a></td>
<td>{if condition="$value->getId() != $current_user->getId()"}<a href="index.php?do=delete_user&user_id={$value->getId()}">Delete</a>{/if}</td>
@ -29,7 +31,10 @@
<h2>Edit a user</h2>
<form method="post" action="index.php?do=add_user" id="edit_user_form">
<p>
<label for="login" class="label-block">Login : </label><input type="text" name="login" id="login" {if condition="$login_post != ''"} value="{$login_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getLogin().'"' : ''} {/if}/>
<label for="login" class="label-block">Login : </label><input type="text" name="login" id="login" {if condition="$login_post != ''"} value="{$login_post}" {else} {$user_id != -1 ? 'value="'.$user_data->getLogin().'"' : ''} {/if}/>
</p>
<p>
<label for="display_name" class="label-block">Displayed name : </label><input type="text" name="display_name" id="display_name" {if condition="$display_name_post != ''"} value="{$display_name_post}" {/else} {$user_id != -& ? 'value="'.$user_data->getDisplayName().'"' : ''} {/if}/>
</p>
<p>
<label for="password" class="label-block">Password : </label><input type="password" name="password" id="password"/>

View File

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