Added a display name field to have a different login and displayed name for users
This commit is contained in:
parent
b927394620
commit
28298c381c
1
TODO
1
TODO
@ -2,7 +2,6 @@
|
|||||||
* Vérification des variables dans les classes + throw exception
|
* Vérification des variables dans les classes + throw exception
|
||||||
* tokens + ban system
|
* tokens + ban system
|
||||||
* remember me
|
* remember me
|
||||||
* Display names
|
|
||||||
* htmlspecialchars => on users objects
|
* htmlspecialchars => on users objects
|
||||||
* Associate a guest with someone
|
* Associate a guest with someone
|
||||||
|
|
||||||
|
@ -3,11 +3,12 @@ require_once('data/config.php');
|
|||||||
require_once('Storage.class.php');
|
require_once('Storage.class.php');
|
||||||
|
|
||||||
class User extends Storage {
|
class User extends Storage {
|
||||||
protected $id, $login, $password, $admin;
|
protected $id, $login, $display_name, $password, $admin;
|
||||||
protected $TABLE_NAME = "Users";
|
protected $TABLE_NAME = "Users";
|
||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
'id'=>'key',
|
'id'=>'key',
|
||||||
'login'=>'string',
|
'login'=>'string',
|
||||||
|
'display_name'=>'string',
|
||||||
'password'=>'password',
|
'password'=>'password',
|
||||||
'admin'=>'bool'
|
'admin'=>'bool'
|
||||||
);
|
);
|
||||||
@ -20,6 +21,10 @@ class User extends Storage {
|
|||||||
return $this->login;
|
return $this->login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDisplayName() {
|
||||||
|
return $this->display_name;
|
||||||
|
}
|
||||||
|
|
||||||
public function getId() {
|
public function getId() {
|
||||||
return $this->id;
|
return $this->id;
|
||||||
}
|
}
|
||||||
@ -36,6 +41,10 @@ class User extends Storage {
|
|||||||
$this->login = $login;
|
$this->login = $login;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setDisplayName($display_name) {
|
||||||
|
$this->display_name = $display_name;
|
||||||
|
}
|
||||||
|
|
||||||
public function setPassword($password) {
|
public function setPassword($password) {
|
||||||
$this->password = $password;
|
$this->password = $password;
|
||||||
}
|
}
|
||||||
@ -56,6 +65,7 @@ class User extends Storage {
|
|||||||
$user_data = $this->load(array('login'=>$this->login));
|
$user_data = $this->load(array('login'=>$this->login));
|
||||||
if(count($user_data) == 1) {
|
if(count($user_data) == 1) {
|
||||||
$this->setId($user_data[0]['id']);
|
$this->setId($user_data[0]['id']);
|
||||||
|
$this->setDisplayName($user_data[0]['admin']);
|
||||||
$this->setAdmin($user_data[0]['admin']);
|
$this->setAdmin($user_data[0]['admin']);
|
||||||
$this->setPassword($user_data[0]['password']);
|
$this->setPassword($user_data[0]['password']);
|
||||||
|
|
||||||
@ -67,7 +77,7 @@ class User extends Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function sessionStore() {
|
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) {
|
public function sessionRestore($data, $serialized = false) {
|
||||||
@ -78,6 +88,7 @@ class User extends Storage {
|
|||||||
|
|
||||||
$this->setId($user_data['id']);
|
$this->setId($user_data['id']);
|
||||||
$this->setLogin($user_data['login']);
|
$this->setLogin($user_data['login']);
|
||||||
|
$this->setDisplayName($user_data['display_name']);
|
||||||
$this->setPassword($user_data['password']);
|
$this->setPassword($user_data['password']);
|
||||||
$this->setAdmin($user_data['admin']);
|
$this->setAdmin($user_data['admin']);
|
||||||
}
|
}
|
||||||
@ -99,6 +110,7 @@ class User extends Storage {
|
|||||||
if(count($fetch) > 0) {
|
if(count($fetch) > 0) {
|
||||||
$this->setId($fetch[0]['id']);
|
$this->setId($fetch[0]['id']);
|
||||||
$this->setLogin($fetch[0]['login']);
|
$this->setLogin($fetch[0]['login']);
|
||||||
|
$this->setDisplayName($fetch[0]['display_name']);
|
||||||
$this->setPassword($fetch[0]['password']);
|
$this->setPassword($fetch[0]['password']);
|
||||||
$this->setAdmin($fetch[0]['admin']);
|
$this->setAdmin($fetch[0]['admin']);
|
||||||
|
|
||||||
|
@ -91,12 +91,13 @@
|
|||||||
header('location: index.php');
|
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();
|
$user = new User();
|
||||||
if(!empty($_POST['user_id'])) {
|
if(!empty($_POST['user_id'])) {
|
||||||
$user->setId($_POST['user_id']);
|
$user->setId($_POST['user_id']);
|
||||||
}
|
}
|
||||||
$user->setLogin($_POST['login']);
|
$user->setLogin($_POST['login']);
|
||||||
|
$user->setDisplayName($_POST['login']);
|
||||||
if(!empty($_POST['password'])) {
|
if(!empty($_POST['password'])) {
|
||||||
$user->setPassword($user->encrypt($_POST['password']));
|
$user->setPassword($user->encrypt($_POST['password']));
|
||||||
}
|
}
|
||||||
@ -125,6 +126,7 @@
|
|||||||
$tpl->assign('view', 'list_users');
|
$tpl->assign('view', 'list_users');
|
||||||
}
|
}
|
||||||
$tpl->assign('login_post', (!empty($_POST['login']) ? htmlspecialchars($_POST['login']) : ''));
|
$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->assign('admin_post', (isset($_POST['admin']) ? (int) $_POST['admin'] : -1));
|
||||||
$tpl->draw('edit_users');
|
$tpl->draw('edit_users');
|
||||||
break;
|
break;
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
$db = new PDO('mysql:host='.$mysql_host.';dbname='.$mysql_db, $mysql_login, $mysql_password);
|
$db = new PDO('mysql:host='.$mysql_host.';dbname='.$mysql_db, $mysql_login, $mysql_password);
|
||||||
|
|
||||||
//Create table "Users"
|
//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 "Invoices" - TODO
|
||||||
//Create table "Payback" - TODO
|
//Create table "Payback" - TODO
|
||||||
@ -58,6 +58,7 @@
|
|||||||
require_once('inc/User.class.php');
|
require_once('inc/User.class.php');
|
||||||
$admin = new User();
|
$admin = new User();
|
||||||
$admin->setLogin($_POST['admin_login']);
|
$admin->setLogin($_POST['admin_login']);
|
||||||
|
$admin->setDisplayName($_POST['admin_display_name']);
|
||||||
$admin->setPassword($admin->encrypt($_POST['admin_password']));
|
$admin->setPassword($admin->encrypt($_POST['admin_password']));
|
||||||
$admin->setAdmin(true);
|
$admin->setAdmin(true);
|
||||||
$admin->save();
|
$admin->save();
|
||||||
@ -116,6 +117,7 @@
|
|||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Administrator</legend>
|
<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_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>
|
<p><label for="admin_password">Password for the admin : </label><input type="password" name="admin_password" id="admin_password"/></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<p class="center"><input <?php echo (!empty($block_form)) ? 'disabled ' : '';?>type="submit" value="Install"></p>
|
<p class="center"><input <?php echo (!empty($block_form)) ? 'disabled ' : '';?>type="submit" value="Install"></p>
|
||||||
|
0
tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
0
tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
0
tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
0
tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
0
tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php
Normal file → Executable file
0
tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php
Normal file → Executable file
0
tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php
Normal file → Executable file
0
tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php
Normal file → Executable file
4
tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
4
tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
@ -15,14 +15,14 @@
|
|||||||
<th>Owes\To</th>
|
<th>Owes\To</th>
|
||||||
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
|
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><?php echo $value1->getLogin();?></th>
|
<th><?php echo $value1->getDisplayName();?></th>
|
||||||
</tr>
|
</tr>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
0
tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
0
tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
@ -11,6 +11,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Id</th>
|
<th>Id</th>
|
||||||
<th>Login</th>
|
<th>Login</th>
|
||||||
|
<th>Display Name</th>
|
||||||
<th>Is admin ?</th>
|
<th>Is admin ?</th>
|
||||||
<th>Edit</th>
|
<th>Edit</th>
|
||||||
<th>Delete</th>
|
<th>Delete</th>
|
||||||
@ -19,6 +20,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{$value->getId()}</td>
|
<td>{$value->getId()}</td>
|
||||||
<td>{$value->getLogin()}</td>
|
<td>{$value->getLogin()}</td>
|
||||||
|
<td>{$value->getDisplayName()}</td>
|
||||||
<td>{$value->getAdmin() ? "Yes" : "No"}</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=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>
|
<td>{if condition="$value->getId() != $current_user->getId()"}<a href="index.php?do=delete_user&user_id={$value->getId()}">Delete</a>{/if}</td>
|
||||||
@ -31,6 +33,9 @@
|
|||||||
<p>
|
<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>
|
||||||
|
<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>
|
<p>
|
||||||
<label for="password" class="label-block">Password : </label><input type="password" name="password" id="password"/>
|
<label for="password" class="label-block">Password : </label><input type="password" name="password" id="password"/>
|
||||||
{if condition="$user_id != -1"}
|
{if condition="$user_id != -1"}
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Owes\To</th>
|
<th>Owes\To</th>
|
||||||
{loop="users"}
|
{loop="users"}
|
||||||
<th>{$value->getLogin()}</th>
|
<th>{$value->getDisplayName()}</th>
|
||||||
{/loop}
|
{/loop}
|
||||||
</tr>
|
</tr>
|
||||||
{loop="users"}
|
{loop="users"}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$value->getLogin()}</th>
|
<th>{$value->getDisplayName()}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{/loop}
|
||||||
</table>
|
</table>
|
||||||
|
Loading…
Reference in New Issue
Block a user