From 28298c381c26c5267ac732d8c3ae918823a31951 Mon Sep 17 00:00:00 2001 From: Phyks Date: Tue, 13 Aug 2013 17:58:14 +0200 Subject: [PATCH] Added a display name field to have a different login and displayed name for users --- TODO | 1 - inc/User.class.php | 16 ++++++++++++++-- index.php | 4 +++- install.php | 4 +++- ...ion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 0 ...ers.af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 0 ...ter.36ba0f7e771a8681573a91518b54b424.rtpl.php | 0 ...der.36ba0f7e771a8681573a91518b54b424.rtpl.php | 0 ...dex.af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 4 ++-- ...ngs.af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 0 tpl/edit_users.html | 7 ++++++- tpl/index.html | 4 ++-- 12 files changed, 30 insertions(+), 10 deletions(-) mode change 100644 => 100755 tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php mode change 100644 => 100755 tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php mode change 100644 => 100755 tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php mode change 100644 => 100755 tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php mode change 100644 => 100755 tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php mode change 100644 => 100755 tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php diff --git a/TODO b/TODO index dbdadb7..265c70b 100755 --- a/TODO +++ b/TODO @@ -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 diff --git a/inc/User.class.php b/inc/User.class.php index d60f578..6ae8964 100644 --- a/inc/User.class.php +++ b/inc/User.class.php @@ -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']); diff --git a/index.php b/index.php index 06d150e..b75794e 100644 --- a/index.php +++ b/index.php @@ -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; diff --git a/install.php b/install.php index ce8e61a..0d7afae 100644 --- a/install.php +++ b/install.php @@ -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 @@
Administrator

/>

+

/>

type="submit" value="Install">

diff --git a/tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/connexion.af3906cfde643ae7f290cfdc51cc9342.rtpl.php old mode 100644 new mode 100755 diff --git a/tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/edit_users.af3906cfde643ae7f290cfdc51cc9342.rtpl.php old mode 100644 new mode 100755 diff --git a/tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php b/tmp/footer.36ba0f7e771a8681573a91518b54b424.rtpl.php old mode 100644 new mode 100755 diff --git a/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php b/tmp/header.36ba0f7e771a8681573a91518b54b424.rtpl.php old mode 100644 new mode 100755 diff --git a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php old mode 100644 new mode 100755 index 2d0cb60..9707ece --- a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php @@ -15,14 +15,14 @@ Owes\To $value1 ){ $counter1++; ?> - getLogin();?> + getDisplayName();?> $value1 ){ $counter1++; ?> - getLogin();?> + getDisplayName();?> diff --git a/tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/settings.af3906cfde643ae7f290cfdc51cc9342.rtpl.php old mode 100644 new mode 100755 diff --git a/tpl/edit_users.html b/tpl/edit_users.html index ab91cce..382b8e5 100644 --- a/tpl/edit_users.html +++ b/tpl/edit_users.html @@ -11,6 +11,7 @@ Id Login + Display Name Is admin ? Edit Delete @@ -19,6 +20,7 @@ {$value->getId()} {$value->getLogin()} + {$value->getDisplayName()} {$value->getAdmin() ? "Yes" : "No"} Edit {if condition="$value->getId() != $current_user->getId()"}Delete{/if} @@ -29,7 +31,10 @@

Edit a user

- + +

+

+

diff --git a/tpl/index.html b/tpl/index.html index 16cf1df..3ebf314 100755 --- a/tpl/index.html +++ b/tpl/index.html @@ -11,12 +11,12 @@ Owes\To {loop="users"} - {$value->getLogin()} + {$value->getDisplayName()} {/loop} {loop="users"} - {$value->getLogin()} + {$value->getDisplayName()} {/loop}