From 599e30def628a91b9308391e939b0c1228069d7e Mon Sep 17 00:00:00 2001 From: Anna BOUDOUL Date: Wed, 7 Dec 2022 19:34:39 +0100 Subject: [PATCH] Test Gateway et controlleur user --- business/ListTask.php | 20 +++++++++++++++- business/Task.php | 2 +- business/User.php | 22 +----------------- controller/CtrlUser.php | 39 +++++++++++++++++++++++++++++++ dal/GatUser.php | 20 ++++++++++++---- model/ModelUser.php | 51 ++++++++++++++++++++++++++++++----------- tests/test.php | 21 +++++++++++++++-- 7 files changed, 132 insertions(+), 43 deletions(-) diff --git a/business/ListTask.php b/business/ListTask.php index d4c6a4d..ffa0dae 100644 --- a/business/ListTask.php +++ b/business/ListTask.php @@ -1,11 +1,13 @@ id = $id; $this->taches = $taches; + $this->owner = $owner; } function get_id() { @@ -16,6 +18,14 @@ $this->id = $id; } + function get_nom() { + return $this->nom; + } + + function set_nom($nom) { + $this->nom = $nom; + } + function get_taches() { return $this->taches; } @@ -23,5 +33,13 @@ function set_taches($taches) { $this->taches = $taches; } + + function get_owner() { + return $this->owner; + } + + function set_owner($owner) { + $this->owner = $owner; + } } ?> \ No newline at end of file diff --git a/business/Task.php b/business/Task.php index 3dc7f69..16bfb63 100644 --- a/business/Task.php +++ b/business/Task.php @@ -7,7 +7,7 @@ private DateTime $dateFin; private string $priorite; - function __construct($id, $titre, $description, $dateDeb, $dateFin, $priorite) { + function __construct($id, $titre, $description, $dateDeb, $dateFin, $priorite){ $this->titre = $titre; $this->description = $description; } diff --git a/business/User.php b/business/User.php index 489fb40..7de66c5 100644 --- a/business/User.php +++ b/business/User.php @@ -1,13 +1,9 @@ id = $id; + function __construct($login) { $this->login = $login; - $this->mdp = $mdp; } function get_login() { @@ -17,21 +13,5 @@ function set_login($login) { $this->login = $login; } - - function get_mdp() { - return $this->mdp; - } - - function set_mdp($mdp) { - $this->mdp = $mdp; - } - - function get_id() { - return $this->id; - } - - function set_id($id) { - $this->id = $id; - } } ?> \ No newline at end of file diff --git a/controller/CtrlUser.php b/controller/CtrlUser.php index e69de29..0a2359a 100644 --- a/controller/CtrlUser.php +++ b/controller/CtrlUser.php @@ -0,0 +1,39 @@ +Reinit(); + break; + case "validationFormulaire": + $this->ValidationFormulaire($dVueEreur); + break; + //mauvaise action + default: + $dVueEreur[] = "Erreur d'appel php"; + require ($rep.$vues['vuephp1']); + break; + } + } catch (PDOException $e) + { + //si erreur BD, pas le cas ici + $dVueEreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['erreur']); + } + catch (Exception $e2) + { + $dVueEreur[] = "Erreur inattendue!!! "; + require ($rep.$vues['erreur']); + } + exit(0); + } + } + +?> \ No newline at end of file diff --git a/dal/GatUser.php b/dal/GatUser.php index 36f6cc2..c1d40c2 100644 --- a/dal/GatUser.php +++ b/dal/GatUser.php @@ -13,19 +13,20 @@ $query = 'INSERT INTO User VALUES (:login, :mdp)'; $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), ':mdp'=>array($pwrd, PDO::PARAM_STR))); - $result = $con->getResults(); + $result = $this->con->getResults(); return $result; } - public function updateLogin($value){ - $query = 'UPDATE User WHERE login = :value'; - $this->con->executeQuery($query, array(':value'=>array($value, PDO::PARAM_STR))); + public function updateLogin($oldValue, $newValue){ + $query = 'UPDATE User SET login = :newValue WHERE login = :oldValue'; + $this->con->executeQuery($query, array(':oldValue'=>array($oldValue, PDO::PARAM_STR), + ':newValue'=>array($newValue, PDO::PARAM_STR))); } public function updateMdp($login, $mdp){ $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); $query = 'UPDATE User SET mdp = :value WHERE login = :login'; - $this->con->executeQuery($query, array(':login'=>array($pwrd, PDO::PARAM_STR), + $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), ':value'=>array($pwrd, PDO::PARAM_STR))); } @@ -41,5 +42,14 @@ $result = $this->con->getResults(); return $result; } + + public function findUser($login, $mdp){ + $pwrd = password_hash($mdp, PASSWORD_BCRYPT, array("cost" => 12)); + $query = 'SELECT login FROM User WHERE login = :login AND mdp = :mdp'; + $this->con->executeQuery($query, array(':login'=>array($login, PDO::PARAM_STR), + ':mdp'=>array($pwrd, PDO::PARAM_STR))); + $result = $this->con->getResults(); + return $result; + } } ?> \ No newline at end of file diff --git a/model/ModelUser.php b/model/ModelUser.php index db18e13..70d4665 100644 --- a/model/ModelUser.php +++ b/model/ModelUser.php @@ -1,4 +1,5 @@ con = $con; $this->gat = new GatUser($con); } + + function connexion($login, $mdp){ + $gat->findUser($login, $mdp); + $_SESSION['login'] = $login; + } + + function deconnexion(){ + session_unset(); + session_destroy(); + $_SESSION = array(); + } + + function isConnected($login){ //teste rôle dans la session, retourne instance d’objet ou booleen + if (isset($_SESSION['login'])) + { + return true; + } + else return false; + } function ajouter($login, $mdp){ - $user = findByLogin($login); + $user = $this->findByLogin($login); if (empty($user)) - $gat->create($login, $mdp); + $this->gat->create($login, $mdp); } function supprimer($login){ - $gat->delete($login); + $this->gat->delete($login); } function modifMdp($login, $mdp){ - $gat->updateMdp($login, $mdp); - } - - function modifLogin($login){ - $user = findByLogin($login); - if (empty($user)) - $gat->updateLogin($login); + $this->gat->updateMdp($login, $mdp); } function findByLogin($login){ + $user = null; if ($login !== " " && $login != null ) - $results = $gat->find($login, "login"); - $user = new User($results["login"]); - return $user; + { + $results = $this->gat->find($login, 'login'); + foreach($results as $row){ + $user = new User($results['login']); + } + return $user; + } + } + + function modifLogin($oldLogin, $newLogin){ + $user = $this->findByLogin($oldLogin); + if (empty($user)) + $this->gat->updateLogin($oldLogin, $newLogin); } } diff --git a/tests/test.php b/tests/test.php index fecc775..7dce820 100644 --- a/tests/test.php +++ b/tests/test.php @@ -1,7 +1,24 @@ create("Nicolas", "tranquiloubilou"); + + // Test Gateway User + + // $gat = new GatUser($con); + // $gat->create('Nicolas', 'tranquilloubilou'); + // $gat->updateLogin('Nicolas', 'RicharlisonR9'); + // $gat->updateMdp('RicharlisonR9', 'hexachampion'); + // $tab = $gat->find('RicharlisonR9', 'login'); + // $gat->delete('RicharlisonR9'); + + // Test Modèle User + + // $mdl = new ModelUser($con); + // $mdl->ajouter('Anna', 'unmdptrescomplique'); + // $mdl->modifLogin('Anna', 'Aeryn'); + // $mdl->modifMdp('Aeryn', 'wtfmec'); + // $mdl->supprimer('Aeryn'); + ?> \ No newline at end of file