From 2177fa0a9cd4b782f7a40cd8c3d5d2811293c39e Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:12:07 +0100 Subject: [PATCH 01/19] =?UTF-8?q?Test=20de=20d=C3=A9ploiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/FrontController.php | 2 +- WEB/Controller/UserController.php | 5 +++-- WEB/Controller/UtilisateurGateway.php | 2 +- WEB/Model/Utilisateur.php | 22 ---------------------- 4 files changed, 5 insertions(+), 26 deletions(-) diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 63c0cc00..8870beaf 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -3,7 +3,7 @@ class FrontController { function __construct() { - global $rep, $vues; + global $rep, $vues, $error; session_start(); // $role=$_SESSION['role']; // $action=$_REQUEST['action']; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 67de1394..8cea6b3c 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -7,7 +7,7 @@ class UserController function __construct() { try{ global $dsn, $rep, $vues, $error; - echo "userController"; + echo "UserController"; $this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; @@ -71,7 +71,8 @@ class UserController throw (new Exception("Email déjà utilisé")); } $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password); + $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); $gateway->insert($Utilisateur); $_SESSION['connected'] = 'true'; $_SESSION['role'] = 'utilisateur'; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 908d92fb..9392ca3f 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -51,7 +51,7 @@ class UtilisateurGateway if ($results == null){ return new Utilisateur("null", "null", "null", false); } - return new Utilisateur($email, $pseudo, $mdp, $estAdmin,false); + return new Utilisateur($email, $pseudo, $mdp, $estAdmin); } public function getMdpByEmail(string $email) : string{ diff --git a/WEB/Model/Utilisateur.php b/WEB/Model/Utilisateur.php index b77d042b..8cc430a0 100644 --- a/WEB/Model/Utilisateur.php +++ b/WEB/Model/Utilisateur.php @@ -13,20 +13,12 @@ class Utilisateur * @param string $mdp * @param bool $estAdmin */ -<<<<<<< HEAD public function __construct(string $email, string $pseudo, string $mdp, bool $estAdmin) -======= - public function __construct(string $email, string $pseudo, string $mdp ,bool $estAdmin) ->>>>>>> d82ece50 (Changement de joueur et admin) { $this->email = $email; $this->pseudo = $pseudo; $this->mdp = $mdp; -<<<<<<< HEAD $this->estAdmin = $estAdmin; -======= - $this->estAdmin=$estAdmin; ->>>>>>> d82ece50 (Changement de joueur et admin) } /** @@ -78,31 +70,17 @@ class Utilisateur } /** -<<<<<<< HEAD - * @return bool -======= * @param bool $estAdmin ->>>>>>> d82ece50 (Changement de joueur et admin) */ public function getEstAdmin(): bool { return $this->estAdmin; } -<<<<<<< HEAD /** * @param bool $estAdmin */ public function setEstAdmin(bool $estAdmin): void { $this->estAdmin = $estAdmin; -======= - - /** - * @param bool $estAdmin - */ - public function setEstAdmin(bool $estAdmin) - { - $this->estAdmin=$estAdmin; ->>>>>>> d82ece50 (Changement de joueur et admin) } } \ No newline at end of file From a241f6147bf11a704517b52a2579b45c8026f496 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:18:09 +0100 Subject: [PATCH 02/19] =?UTF-8?q?Test=20de=20d=C3=A9ploiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/FrontController.php | 36 ++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 8870beaf..c4baf3d4 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -1,15 +1,33 @@ getMessage(); + // require ($rep . $vues['erreur']); + // } + // } + private Connection $con; + function __construct() { + try{ + global $dsn, $rep, $vues, $error; + echo "FrontController"; + $this->con=new Connection ($dsn); + echo "FCconection"; + $action=$_REQUEST['action']; + switch($action) { + case NULL: + require ($rep.$vues['main']); + break; + } } catch (Exception $e) { $error = $e->getMessage(); require ($rep . $vues['erreur']); From 3c2d4d5932250205c771f58109ab9038b917ba45 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:19:03 +0100 Subject: [PATCH 03/19] =?UTF-8?q?Test=20de=20d=C3=A9ploiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/FrontController.php | 36 ++++++++---------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index c4baf3d4..8870beaf 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -1,33 +1,15 @@ getMessage(); - // require ($rep . $vues['erreur']); - // } - // } - private Connection $con; - function __construct() { - try{ - global $dsn, $rep, $vues, $error; - echo "FrontController"; - $this->con=new Connection ($dsn); - echo "FCconection"; - $action=$_REQUEST['action']; - switch($action) { - case NULL: - require ($rep.$vues['main']); - break; - } + function __construct() + { + global $rep, $vues, $error; + session_start(); + // $role=$_SESSION['role']; + // $action=$_REQUEST['action']; + echo "frontController"; + try { + new UserController(); } catch (Exception $e) { $error = $e->getMessage(); require ($rep . $vues['erreur']); From a66c6377001c09c6035790237d5f3206b24b928c Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:23:46 +0100 Subject: [PATCH 04/19] =?UTF-8?q?Test=20de=20d=C3=A9ploiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/UserController.php | 196 +++++++++++++++--------------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 8cea6b3c..5cdad8f1 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,40 +2,40 @@ class UserController { - private Connection $con; + //private Connection $con; function __construct() { try{ - global $dsn, $rep, $vues, $error; echo "UserController"; - $this->con=new Connection ($dsn); + global $dsn, $rep, $vues, $error; + //$this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { case NULL: $this->goToHome(); break; - case "signUp": - $this->signUp(); - break; - case "login": - $this->login(); - break; - case "goToPresentation": - $this->goToPresentation(); - break; - case "goToHome": - $this->goToHome(); - break; - case "goToLogin": - $this->goToLogin(); - break; - case "goToSignUp": - $this->goToSignUp(); - break; - case "goToEnigme": - $this->goToEnigme(); - break; + // case "signUp": + // $this->signUp(); + // break; + // case "login": + // $this->login(); + // break; + // case "goToPresentation": + // $this->goToPresentation(); + // break; + // case "goToHome": + // $this->goToHome(); + // break; + // case "goToLogin": + // $this->goToLogin(); + // break; + // case "goToSignUp": + // $this->goToSignUp(); + // break; + // case "goToEnigme": + // $this->goToEnigme(); + // break; } } catch (PDOException $e) { @@ -48,82 +48,82 @@ class UserController } } - private function signUp() { - global $rep, $vues, $sel, $error; - try { - $gateway = new UtilisateurGateway($this->con); - $validation = new Validation(); - if (! $validation->ValidateEmail($_REQUEST['email'])) { - $error = "Email invalides."; - throw (new Exception("Email non valide")); - } - if(! $validation->ValidateUsername($_REQUEST['username'])){ - $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; - throw(new Exception("Pseudo non valide")); - } - if(! $validation->ValidatePassword($_REQUEST['password'])){ - $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; - throw(new Exception("Mot de passe non valide")); - } - $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($j != null) { - $error = "Email déjà utilisé."; - throw (new Exception("Email déjà utilisé")); - } - $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); - $gateway->insert($Utilisateur); - $_SESSION['connected'] = 'true'; - $_SESSION['role'] = 'utilisateur'; - require ($rep.$vues['main']); - }catch (PDOException $e) - { - $error = "Erreur de connexion à la base de données."; - require ($rep.$vues['erreur']); - } - catch (Exception $e){ - require($rep.$vues['erreur']); - } - } - private function login(){ - global $rep, $vues, $sel, $error; - try { - $gateway = new UtilisateurGateway($this->con); - $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($Utilisateur->getEmail() == null){ - $error = "Utilisateur non trouvé."; - throw new Exception("Utilisateur introuvable"); - } - $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - if (password_verify($mdp, $_REQUEST['password'])){ - $error = "Mot de passe incorrect."; - throw new Exception("Mot de passe invalide"); - } - $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); - if ($estAdmin == true) { - $_SESSION['role'] = "admin"; - } - else{ - $_SESSION['role'] = "utilisateur"; - } + // private function signUp() { + // global $rep, $vues, $sel, $error; + // try { + // $gateway = new UtilisateurGateway($this->con); + // $validation = new Validation(); + // if (! $validation->ValidateEmail($_REQUEST['email'])) { + // $error = "Email invalides."; + // throw (new Exception("Email non valide")); + // } + // if(! $validation->ValidateUsername($_REQUEST['username'])){ + // $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; + // throw(new Exception("Pseudo non valide")); + // } + // if(! $validation->ValidatePassword($_REQUEST['password'])){ + // $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + // throw(new Exception("Mot de passe non valide")); + // } + // $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); + // if ($j != null) { + // $error = "Email déjà utilisé."; + // throw (new Exception("Email déjà utilisé")); + // } + // $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + // $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + // $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + // $gateway->insert($Utilisateur); + // $_SESSION['connected'] = 'true'; + // $_SESSION['role'] = 'utilisateur'; + // require ($rep.$vues['main']); + // }catch (PDOException $e) + // { + // $error = "Erreur de connexion à la base de données."; + // require ($rep.$vues['erreur']); + // } + // catch (Exception $e){ + // require($rep.$vues['erreur']); + // } + // } + // private function login(){ + // global $rep, $vues, $sel, $error; + // try { + // $gateway = new UtilisateurGateway($this->con); + // $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); + // if ($Utilisateur->getEmail() == null){ + // $error = "Utilisateur non trouvé."; + // throw new Exception("Utilisateur introuvable"); + // } + // $mdp = $gateway->getMdpByEmail($_REQUEST['email']); + // if (password_verify($mdp, $_REQUEST['password'])){ + // $error = "Mot de passe incorrect."; + // throw new Exception("Mot de passe invalide"); + // } + // $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); + // if ($estAdmin == true) { + // $_SESSION['role'] = "admin"; + // } + // else{ + // $_SESSION['role'] = "utilisateur"; + // } - $_SESSION['connected'] = 'true'; - require ($rep.$vues['main']); - }catch (Exception $e){ - require($rep.$vues['erreur']); - } - } + // $_SESSION['connected'] = 'true'; + // require ($rep.$vues['main']); + // }catch (Exception $e){ + // require($rep.$vues['erreur']); + // } + // } - private function goToPresentation() { - global $rep, $vues, $error; - try { - require ($rep.$vues['presentation']); - }catch (Exception $e){ - $error = "Erreur Inconnue"; - require($rep.$vues['erreur']); - } - } + // private function goToPresentation() { + // global $rep, $vues, $error; + // try { + // require ($rep.$vues['presentation']); + // }catch (Exception $e){ + // $error = "Erreur Inconnue"; + // require($rep.$vues['erreur']); + // } + // } private function goToHome() { global $rep, $vues, $error; From 3b5666cb44646c2800799e184d2e6ebabce361ca Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:34:43 +0100 Subject: [PATCH 05/19] =?UTF-8?q?Testd=20de=20d=C3=A9ploiment?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Config/Config.php | 2 +- WEB/Config/Connection.php | 39 +++--- WEB/Controller/UserController.php | 194 +++++++++++++++--------------- 3 files changed, 119 insertions(+), 116 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index e0c6b63b..78c5f776 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,7 +14,7 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -$dsn = './Model/scripted.db'; +$dsn = './Model/scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 0ecf2b5e..45677c0a 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -19,23 +19,26 @@ class Connection extends SQLite3 { - private $stmt; - private $result; - function __construct($dsn) - { - $this->open($dsn); - } + private $stmt; + private $result; + function __construct($dsn) + { + $this->enableExceptions(true); + parent::__construct($dsn, SQLITE3_OPEN_READWRITE); + } - public function executeQuery(string $query, array $parameters = []) :bool { - $this->stmt = $this->prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } - $this->result=$this->stmt->execute(); - return $this->result; - } + public function executeQuery(string $query, array $parameters = []): bool + { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + $this->result = $this->stmt->execute(); + return $this->result; + } - public function getResults(): array { - return $this->result->fetchArray(); - } -} \ No newline at end of file + public function getResults(): array + { + return $this->result->fetchArray(); + } +} diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 5cdad8f1..18fd13c6 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,40 +2,40 @@ class UserController { - //private Connection $con; + private Connection $con; function __construct() { try{ echo "UserController"; global $dsn, $rep, $vues, $error; - //$this->con=new Connection ($dsn); + $this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { case NULL: $this->goToHome(); break; - // case "signUp": - // $this->signUp(); - // break; - // case "login": - // $this->login(); - // break; - // case "goToPresentation": - // $this->goToPresentation(); - // break; - // case "goToHome": - // $this->goToHome(); - // break; - // case "goToLogin": - // $this->goToLogin(); - // break; - // case "goToSignUp": - // $this->goToSignUp(); - // break; - // case "goToEnigme": - // $this->goToEnigme(); - // break; + case "signUp": + $this->signUp(); + break; + case "login": + $this->login(); + break; + case "goToPresentation": + $this->goToPresentation(); + break; + case "goToHome": + $this->goToHome(); + break; + case "goToLogin": + $this->goToLogin(); + break; + case "goToSignUp": + $this->goToSignUp(); + break; + case "goToEnigme": + $this->goToEnigme(); + break; } } catch (PDOException $e) { @@ -48,82 +48,82 @@ class UserController } } - // private function signUp() { - // global $rep, $vues, $sel, $error; - // try { - // $gateway = new UtilisateurGateway($this->con); - // $validation = new Validation(); - // if (! $validation->ValidateEmail($_REQUEST['email'])) { - // $error = "Email invalides."; - // throw (new Exception("Email non valide")); - // } - // if(! $validation->ValidateUsername($_REQUEST['username'])){ - // $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; - // throw(new Exception("Pseudo non valide")); - // } - // if(! $validation->ValidatePassword($_REQUEST['password'])){ - // $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; - // throw(new Exception("Mot de passe non valide")); - // } - // $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); - // if ($j != null) { - // $error = "Email déjà utilisé."; - // throw (new Exception("Email déjà utilisé")); - // } - // $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - // $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); - // $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); - // $gateway->insert($Utilisateur); - // $_SESSION['connected'] = 'true'; - // $_SESSION['role'] = 'utilisateur'; - // require ($rep.$vues['main']); - // }catch (PDOException $e) - // { - // $error = "Erreur de connexion à la base de données."; - // require ($rep.$vues['erreur']); - // } - // catch (Exception $e){ - // require($rep.$vues['erreur']); - // } - // } - // private function login(){ - // global $rep, $vues, $sel, $error; - // try { - // $gateway = new UtilisateurGateway($this->con); - // $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); - // if ($Utilisateur->getEmail() == null){ - // $error = "Utilisateur non trouvé."; - // throw new Exception("Utilisateur introuvable"); - // } - // $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - // if (password_verify($mdp, $_REQUEST['password'])){ - // $error = "Mot de passe incorrect."; - // throw new Exception("Mot de passe invalide"); - // } - // $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); - // if ($estAdmin == true) { - // $_SESSION['role'] = "admin"; - // } - // else{ - // $_SESSION['role'] = "utilisateur"; - // } + private function signUp() { + global $rep, $vues, $sel, $error; + try { + $gateway = new UtilisateurGateway($this->con); + $validation = new Validation(); + if (! $validation->ValidateEmail($_REQUEST['email'])) { + $error = "Email invalides."; + throw (new Exception("Email non valide")); + } + if(! $validation->ValidateUsername($_REQUEST['username'])){ + $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; + throw(new Exception("Pseudo non valide")); + } + if(! $validation->ValidatePassword($_REQUEST['password'])){ + $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + throw(new Exception("Mot de passe non valide")); + } + $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($j != null) { + $error = "Email déjà utilisé."; + throw (new Exception("Email déjà utilisé")); + } + $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + $gateway->insert($Utilisateur); + $_SESSION['connected'] = 'true'; + $_SESSION['role'] = 'utilisateur'; + require ($rep.$vues['main']); + }catch (PDOException $e) + { + $error = "Erreur de connexion à la base de données."; + require ($rep.$vues['erreur']); + } + catch (Exception $e){ + require($rep.$vues['erreur']); + } + } + private function login(){ + global $rep, $vues, $sel, $error; + try { + $gateway = new UtilisateurGateway($this->con); + $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($Utilisateur->getEmail() == null){ + $error = "Utilisateur non trouvé."; + throw new Exception("Utilisateur introuvable"); + } + $mdp = $gateway->getMdpByEmail($_REQUEST['email']); + if (password_verify($mdp, $_REQUEST['password'])){ + $error = "Mot de passe incorrect."; + throw new Exception("Mot de passe invalide"); + } + $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); + if ($estAdmin == true) { + $_SESSION['role'] = "admin"; + } + else{ + $_SESSION['role'] = "utilisateur"; + } - // $_SESSION['connected'] = 'true'; - // require ($rep.$vues['main']); - // }catch (Exception $e){ - // require($rep.$vues['erreur']); - // } - // } + $_SESSION['connected'] = 'true'; + require ($rep.$vues['main']); + }catch (Exception $e){ + require($rep.$vues['erreur']); + } + } - // private function goToPresentation() { - // global $rep, $vues, $error; - // try { - // require ($rep.$vues['presentation']); - // }catch (Exception $e){ - // $error = "Erreur Inconnue"; - // require($rep.$vues['erreur']); - // } - // } + private function goToPresentation() { + global $rep, $vues, $error; + try { + require ($rep.$vues['presentation']); + }catch (Exception $e){ + $error = "Erreur Inconnue"; + require($rep.$vues['erreur']); + } + } private function goToHome() { global $rep, $vues, $error; From 6758b980858fd2cad74dcfebed71e99256071c93 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:37:43 +0100 Subject: [PATCH 06/19] test --- WEB/Config/Connection.php | 41 +++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 45677c0a..18c1fbc6 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -19,26 +19,33 @@ class Connection extends SQLite3 { - private $stmt; - private $result; - function __construct($dsn) + private $stmt; + private $result; + function __construct($dsn) { + global $rep, $vues, $error; $this->enableExceptions(true); - parent::__construct($dsn, SQLITE3_OPEN_READWRITE); - } - public function executeQuery(string $query, array $parameters = []): bool - { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); + try + { + parent::__construct($dsn, SQLITE3_OPEN_READWRITE ); + } + catch(Exception $e) { + $error = $e->getMessage(); + require ($rep.$vues['erreur']); } - $this->result = $this->stmt->execute(); - return $this->result; } - public function getResults(): array - { - return $this->result->fetchArray(); - } -} + public function executeQuery(string $query, array $parameters = []) :bool { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + $this->result=$this->stmt->execute(); + return $this->result; + } + + public function getResults(): array { + return $this->result->fetchArray(); + } +} \ No newline at end of file From 60d03f7d1c9d5dafd54cf749119e8c90e3dfb165 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:49:32 +0100 Subject: [PATCH 07/19] Test --- WEB/Config/Config.php | 3 +- WEB/Config/Connection.php | 81 ++++++++++++--------------- WEB/Controller/UtilisateurGateway.php | 16 +++--- WEB/index.php | 1 - 4 files changed, 46 insertions(+), 55 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 78c5f776..33a750ea 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,7 +14,8 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -$dsn = './Model/scripted.db'; +$dsn = 'sqlite:./Model/scripted.db'; +// $dsn = './Model/scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 18c1fbc6..77ec1775 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -1,51 +1,42 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } +class Connection extends PDO { + private $stmt; + public function __construct(string $dsn) { + parent::__construct($dsn); + echo "connection"; + $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } -// public function executeQuery(string $query, array $parameters = []) :bool { -// $this->stmt = parent::prepare($query); -// foreach ($parameters as $name => $value) { -// $this->stmt->bindValue($name, $value[0], $value[1]); } -// return $this->stmt->execute(); } -// public function getResults(): array { -// return $this->stmt->fetchall(); -// } -// } - -class Connection extends SQLite3 -{ - private $stmt; - private $result; - function __construct($dsn) - { - global $rep, $vues, $error; - $this->enableExceptions(true); - - try - { - parent::__construct($dsn, SQLITE3_OPEN_READWRITE ); - } - catch(Exception $e) { - $error = $e->getMessage(); - require ($rep.$vues['erreur']); - } + public function executeQuery(string $query, array $parameters = []) :bool { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); } + return $this->stmt->execute(); } + public function getResults(): array { + return $this->stmt->fetchall(); } +} + +// class Connection extends SQLite3 +// { +// private $stmt; +// private $result; +// function __construct($dsn) +// { +// parent::__construct($dsn, SQLITE3_OPEN_READWRITE ); +// $this->enableExceptions(true); +// } - public function executeQuery(string $query, array $parameters = []) :bool { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); - } - $this->result=$this->stmt->execute(); - return $this->result; - } +// public function executeQuery(string $query, array $parameters = []) :bool { +// $this->stmt = parent::prepare($query); +// foreach ($parameters as $name => $value) { +// $this->stmt->bindValue($name, $value[0], $value[1]); +// } +// $this->result=$this->stmt->execute(); +// return $this->result; +// } - public function getResults(): array { - return $this->result->fetchArray(); - } -} \ No newline at end of file +// public function getResults(): array { +// return $this->result->fetchArray(); +// } +// } \ No newline at end of file diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 9392ca3f..a7265fab 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -22,16 +22,16 @@ class UtilisateurGateway public function insert(Utilisateur $utilisateur) : void{ $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; $this->con->executeQuery($query, array( - ':email' => array($utilisateur->getEmail(),SQLITE3_TEXT), - ':pseudo' => array($utilisateur->getPseudo(),SQLITE3_TEXT), - ':mdp' => array($utilisateur->getMdp(),SQLITE3_TEXT), - ':estAdmin' => array($utilisateur->getEstAdmin(),SQLITE3_INTEGER))); + ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), + ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), + ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), + ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); } public function delete(string $email) : void{ $query = "DELETE FROM utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email ,SQLITE3_TEXT) + ':email' => array($email ,PDO::PARAM_STR) )); } @@ -39,7 +39,7 @@ class UtilisateurGateway global $error; $query = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -58,7 +58,7 @@ class UtilisateurGateway global $error; $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -75,7 +75,7 @@ class UtilisateurGateway global $error; $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,SQLITE3_TEXT) + ':email' => array($email,PDO::PARAM_STR) )); $results=$this->con->getResults(); foreach ($results as $row) { diff --git a/WEB/index.php b/WEB/index.php index a9704cb1..6ead10ee 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -20,7 +20,6 @@ Autoload::charger(); echo "test"; $control = new FrontController(); - //session_regenerate_id(true); // session_unset(); // session_destroy(); From a5daa35d325bac558d35f34ea32f42b731bce6d3 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 10:50:41 +0100 Subject: [PATCH 08/19] TEST --- WEB/Config/Config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 33a750ea..ccf38b59 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,7 +14,7 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -$dsn = 'sqlite:./Model/scripted.db'; +$dsn = 'sqlite:/Model/scripted.db'; // $dsn = './Model/scripted.db'; //Sel de hashage From 694f7d20d5a9cbcd3b28480b03ce813735579da4 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:00:08 +0100 Subject: [PATCH 09/19] Test --- WEB/Config/Config.php | 3 +- WEB/Config/Connection.php | 41 +++++--- WEB/Controller/UserController.php | 144 +++++++++++++------------- WEB/Controller/UtilisateurGateway.php | 142 ++++++++++++------------- 4 files changed, 168 insertions(+), 162 deletions(-) diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index ccf38b59..78c5f776 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -14,8 +14,7 @@ $rep = __DIR__ . '/../'; // $password = 'p'; // SQULITE3 -$dsn = 'sqlite:/Model/scripted.db'; -// $dsn = './Model/scripted.db'; +$dsn = './Model/scripted.db'; //Sel de hashage $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 77ec1775..9223e8ea 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -1,21 +1,21 @@ setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } +// class Connection extends PDO { +// private $stmt; +// public function __construct(string $dsn) { +// parent::__construct($dsn); +// echo "connection"; +// $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } - public function executeQuery(string $query, array $parameters = []) :bool { - $this->stmt = parent::prepare($query); - foreach ($parameters as $name => $value) { - $this->stmt->bindValue($name, $value[0], $value[1]); } - return $this->stmt->execute(); } - public function getResults(): array { - return $this->stmt->fetchall(); - } -} +// public function executeQuery(string $query, array $parameters = []) :bool { +// $this->stmt = parent::prepare($query); +// foreach ($parameters as $name => $value) { +// $this->stmt->bindValue($name, $value[0], $value[1]); } +// return $this->stmt->execute(); } +// public function getResults(): array { +// return $this->stmt->fetchall(); +// } +// } // class Connection extends SQLite3 // { @@ -23,7 +23,7 @@ class Connection extends PDO { // private $result; // function __construct($dsn) // { -// parent::__construct($dsn, SQLITE3_OPEN_READWRITE ); +// $this->open($dsn); // $this->enableExceptions(true); // } @@ -39,4 +39,11 @@ class Connection extends PDO { // public function getResults(): array { // return $this->result->fetchArray(); // } -// } \ No newline at end of file +// } + +class Connection extends SQLite3{ + function __construct() + { + $this->open("./Model/scripted.db"); + } +} \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 18fd13c6..e472a4e0 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -8,19 +8,19 @@ class UserController try{ echo "UserController"; global $dsn, $rep, $vues, $error; - $this->con=new Connection ($dsn); + $this->con=new Connection (); echo "USconection"; $action=$_REQUEST['action']; switch($action) { case NULL: $this->goToHome(); break; - case "signUp": - $this->signUp(); - break; - case "login": - $this->login(); - break; + // case "signUp": + // $this->signUp(); + // break; + // case "login": + // $this->login(); + // break; case "goToPresentation": $this->goToPresentation(); break; @@ -48,72 +48,72 @@ class UserController } } - private function signUp() { - global $rep, $vues, $sel, $error; - try { - $gateway = new UtilisateurGateway($this->con); - $validation = new Validation(); - if (! $validation->ValidateEmail($_REQUEST['email'])) { - $error = "Email invalides."; - throw (new Exception("Email non valide")); - } - if(! $validation->ValidateUsername($_REQUEST['username'])){ - $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; - throw(new Exception("Pseudo non valide")); - } - if(! $validation->ValidatePassword($_REQUEST['password'])){ - $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; - throw(new Exception("Mot de passe non valide")); - } - $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($j != null) { - $error = "Email déjà utilisé."; - throw (new Exception("Email déjà utilisé")); - } - $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); - $gateway->insert($Utilisateur); - $_SESSION['connected'] = 'true'; - $_SESSION['role'] = 'utilisateur'; - require ($rep.$vues['main']); - }catch (PDOException $e) - { - $error = "Erreur de connexion à la base de données."; - require ($rep.$vues['erreur']); - } - catch (Exception $e){ - require($rep.$vues['erreur']); - } - } - private function login(){ - global $rep, $vues, $sel, $error; - try { - $gateway = new UtilisateurGateway($this->con); - $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); - if ($Utilisateur->getEmail() == null){ - $error = "Utilisateur non trouvé."; - throw new Exception("Utilisateur introuvable"); - } - $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - if (password_verify($mdp, $_REQUEST['password'])){ - $error = "Mot de passe incorrect."; - throw new Exception("Mot de passe invalide"); - } - $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); - if ($estAdmin == true) { - $_SESSION['role'] = "admin"; - } - else{ - $_SESSION['role'] = "utilisateur"; - } + // private function signUp() { + // global $rep, $vues, $sel, $error; + // try { + // $gateway = new UtilisateurGateway($this->con); + // $validation = new Validation(); + // if (! $validation->ValidateEmail($_REQUEST['email'])) { + // $error = "Email invalides."; + // throw (new Exception("Email non valide")); + // } + // if(! $validation->ValidateUsername($_REQUEST['username'])){ + // $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; + // throw(new Exception("Pseudo non valide")); + // } + // if(! $validation->ValidatePassword($_REQUEST['password'])){ + // $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + // throw(new Exception("Mot de passe non valide")); + // } + // $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); + // if ($j != null) { + // $error = "Email déjà utilisé."; + // throw (new Exception("Email déjà utilisé")); + // } + // $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + // $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + // $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + // $gateway->insert($Utilisateur); + // $_SESSION['connected'] = 'true'; + // $_SESSION['role'] = 'utilisateur'; + // require ($rep.$vues['main']); + // }catch (PDOException $e) + // { + // $error = "Erreur de connexion à la base de données."; + // require ($rep.$vues['erreur']); + // } + // catch (Exception $e){ + // require($rep.$vues['erreur']); + // } + // } + // private function login(){ + // global $rep, $vues, $sel, $error; + // try { + // $gateway = new UtilisateurGateway($this->con); + // $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); + // if ($Utilisateur->getEmail() == null){ + // $error = "Utilisateur non trouvé."; + // throw new Exception("Utilisateur introuvable"); + // } + // $mdp = $gateway->getMdpByEmail($_REQUEST['email']); + // if (password_verify($mdp, $_REQUEST['password'])){ + // $error = "Mot de passe incorrect."; + // throw new Exception("Mot de passe invalide"); + // } + // $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); + // if ($estAdmin == true) { + // $_SESSION['role'] = "admin"; + // } + // else{ + // $_SESSION['role'] = "utilisateur"; + // } - $_SESSION['connected'] = 'true'; - require ($rep.$vues['main']); - }catch (Exception $e){ - require($rep.$vues['erreur']); - } - } + // $_SESSION['connected'] = 'true'; + // require ($rep.$vues['main']); + // }catch (Exception $e){ + // require($rep.$vues['erreur']); + // } + // } private function goToPresentation() { global $rep, $vues, $error; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index a7265fab..dcd105d1 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -19,81 +19,81 @@ class UtilisateurGateway $this->con = $con; } - public function insert(Utilisateur $utilisateur) : void{ - $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; - $this->con->executeQuery($query, array( - ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), - ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), - ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), - ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); - } + // public function insert(Utilisateur $utilisateur) : void{ + // $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; + // $this->con->executeQuery($query, array( + // ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), + // ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), + // ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), + // ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); + // } - public function delete(string $email) : void{ - $query = "DELETE FROM utilisateur WHERE email=:email"; - $this->con->executeQuery($query, array( - ':email' => array($email ,PDO::PARAM_STR) - )); - } + // public function delete(string $email) : void{ + // $query = "DELETE FROM utilisateur WHERE email=:email"; + // $this->con->executeQuery($query, array( + // ':email' => array($email ,PDO::PARAM_STR) + // )); + // } - public function getUtilisateurByEmail(string $email) : Utilisateur{ - global $error; - $query = "SELECT * FROM Utilisateur WHERE email=:email"; - $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) - )); - $results=$this->con->getResults(); - foreach ($results as $row) { - $email=$row['email']; - $pseudo=$row['pseudo']; - $mdp=$row['mdp']; - $estAdmin=$row['estAdmin']; - } - if ($results == null){ - return new Utilisateur("null", "null", "null", false); - } - return new Utilisateur($email, $pseudo, $mdp, $estAdmin); - } + // public function getUtilisateurByEmail(string $email) : Utilisateur{ + // global $error; + // $query = "SELECT * FROM Utilisateur WHERE email=:email"; + // $this->con->executeQuery($query, array( + // ':email' => array($email,PDO::PARAM_STR) + // )); + // $results=$this->con->getResults(); + // foreach ($results as $row) { + // $email=$row['email']; + // $pseudo=$row['pseudo']; + // $mdp=$row['mdp']; + // $estAdmin=$row['estAdmin']; + // } + // if ($results == null){ + // return new Utilisateur("null", "null", "null", false); + // } + // return new Utilisateur($email, $pseudo, $mdp, $estAdmin); + // } - public function getMdpByEmail(string $email) : string{ - global $error; - $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; - $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) - )); - $results=$this->con->getResults(); - foreach ($results as $row) { - $mdp=$row['mdp']; - } - if ($results == null){ - $error = "Mot de passe non trouvé."; - throw new Exception("Mots de passe Incorrect"); - } - return $mdp; - } + // public function getMdpByEmail(string $email) : string{ + // global $error; + // $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; + // $this->con->executeQuery($query, array( + // ':email' => array($email,PDO::PARAM_STR) + // )); + // $results=$this->con->getResults(); + // foreach ($results as $row) { + // $mdp=$row['mdp']; + // } + // if ($results == null){ + // $error = "Mot de passe non trouvé."; + // throw new Exception("Mots de passe Incorrect"); + // } + // return $mdp; + // } - public function getEstAdminByEmail(string $email) : bool{ - global $error; - $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; - $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) - )); - $results=$this->con->getResults(); - foreach ($results as $row) { - $estAdmin=$row['estAdmin']; - } - return $estAdmin; - } + // public function getEstAdminByEmail(string $email) : bool{ + // global $error; + // $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; + // $this->con->executeQuery($query, array( + // ':email' => array($email,PDO::PARAM_STR) + // )); + // $results=$this->con->getResults(); + // foreach ($results as $row) { + // $estAdmin=$row['estAdmin']; + // } + // return $estAdmin; + // } - public function showAll() : void{ - $query = "SELECT * FROM Utilisateur"; - $this->con->executeQuery($query); - $results=$this->con->getResults(); - foreach ($results as $row) { - echo $row['email'] . '
'; - echo $row['pseudo'] . '
'; - echo $row['mdp'] . '
'; - echo $row['estAdmin'] . '
'; - } + // public function showAll() : void{ + // $query = "SELECT * FROM Utilisateur"; + // $this->con->executeQuery($query); + // $results=$this->con->getResults(); + // foreach ($results as $row) { + // echo $row['email'] . '
'; + // echo $row['pseudo'] . '
'; + // echo $row['mdp'] . '
'; + // echo $row['estAdmin'] . '
'; + // } - } + // } } \ No newline at end of file From 62c0950c540dd0dd773ea00ec0d66a656351b8a2 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:02:58 +0100 Subject: [PATCH 10/19] test --- WEB/index.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WEB/index.php b/WEB/index.php index 6ead10ee..02769bd9 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -18,7 +18,9 @@ Autoload::charger(); // } echo "test"; -$control = new FrontController(); +$db = new Connection(); +echo "test2"; +// $control = new FrontController(); //session_regenerate_id(true); // session_unset(); From 43821baf34a4398d72cc1a4f09389e6f4551470f Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:08:05 +0100 Subject: [PATCH 11/19] Test --- WEB/Config/Connection.php | 54 +++++----- WEB/Controller/UserController.php | 144 +++++++++++++------------- WEB/Controller/UtilisateurGateway.php | 142 ++++++++++++------------- WEB/index.php | 2 +- 4 files changed, 171 insertions(+), 171 deletions(-) diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 9223e8ea..987a2594 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -17,33 +17,33 @@ // } // } -// class Connection extends SQLite3 -// { -// private $stmt; -// private $result; -// function __construct($dsn) -// { -// $this->open($dsn); -// $this->enableExceptions(true); -// } +class Connection extends SQLite3 +{ + private $stmt; + private $result; + function __construct($dsn) + { + $this->open($dsn); + $this->enableExceptions(true); + } -// public function executeQuery(string $query, array $parameters = []) :bool { -// $this->stmt = parent::prepare($query); -// foreach ($parameters as $name => $value) { -// $this->stmt->bindValue($name, $value[0], $value[1]); -// } -// $this->result=$this->stmt->execute(); -// return $this->result; -// } + public function executeQuery(string $query, array $parameters = []) :bool { + $this->stmt = parent::prepare($query); + foreach ($parameters as $name => $value) { + $this->stmt->bindValue($name, $value[0], $value[1]); + } + $this->result=$this->stmt->execute(); + return $this->result; + } -// public function getResults(): array { -// return $this->result->fetchArray(); -// } -// } + public function getResults(): array { + return $this->result->fetchArray(); + } +} -class Connection extends SQLite3{ - function __construct() - { - $this->open("./Model/scripted.db"); - } -} \ No newline at end of file +// class Connection extends SQLite3{ +// function __construct() +// { +// $this->open("./Model/scripted.db"); +// } +// } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index e472a4e0..18fd13c6 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -8,19 +8,19 @@ class UserController try{ echo "UserController"; global $dsn, $rep, $vues, $error; - $this->con=new Connection (); + $this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { case NULL: $this->goToHome(); break; - // case "signUp": - // $this->signUp(); - // break; - // case "login": - // $this->login(); - // break; + case "signUp": + $this->signUp(); + break; + case "login": + $this->login(); + break; case "goToPresentation": $this->goToPresentation(); break; @@ -48,72 +48,72 @@ class UserController } } - // private function signUp() { - // global $rep, $vues, $sel, $error; - // try { - // $gateway = new UtilisateurGateway($this->con); - // $validation = new Validation(); - // if (! $validation->ValidateEmail($_REQUEST['email'])) { - // $error = "Email invalides."; - // throw (new Exception("Email non valide")); - // } - // if(! $validation->ValidateUsername($_REQUEST['username'])){ - // $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; - // throw(new Exception("Pseudo non valide")); - // } - // if(! $validation->ValidatePassword($_REQUEST['password'])){ - // $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; - // throw(new Exception("Mot de passe non valide")); - // } - // $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); - // if ($j != null) { - // $error = "Email déjà utilisé."; - // throw (new Exception("Email déjà utilisé")); - // } - // $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - // $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); - // $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); - // $gateway->insert($Utilisateur); - // $_SESSION['connected'] = 'true'; - // $_SESSION['role'] = 'utilisateur'; - // require ($rep.$vues['main']); - // }catch (PDOException $e) - // { - // $error = "Erreur de connexion à la base de données."; - // require ($rep.$vues['erreur']); - // } - // catch (Exception $e){ - // require($rep.$vues['erreur']); - // } - // } - // private function login(){ - // global $rep, $vues, $sel, $error; - // try { - // $gateway = new UtilisateurGateway($this->con); - // $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); - // if ($Utilisateur->getEmail() == null){ - // $error = "Utilisateur non trouvé."; - // throw new Exception("Utilisateur introuvable"); - // } - // $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - // if (password_verify($mdp, $_REQUEST['password'])){ - // $error = "Mot de passe incorrect."; - // throw new Exception("Mot de passe invalide"); - // } - // $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); - // if ($estAdmin == true) { - // $_SESSION['role'] = "admin"; - // } - // else{ - // $_SESSION['role'] = "utilisateur"; - // } + private function signUp() { + global $rep, $vues, $sel, $error; + try { + $gateway = new UtilisateurGateway($this->con); + $validation = new Validation(); + if (! $validation->ValidateEmail($_REQUEST['email'])) { + $error = "Email invalides."; + throw (new Exception("Email non valide")); + } + if(! $validation->ValidateUsername($_REQUEST['username'])){ + $error = "Nom d'utilisateur invalides. Il ne doit pas contenir de caractère spéciaux."; + throw(new Exception("Pseudo non valide")); + } + if(! $validation->ValidatePassword($_REQUEST['password'])){ + $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + throw(new Exception("Mot de passe non valide")); + } + $j = $gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($j != null) { + $error = "Email déjà utilisé."; + throw (new Exception("Email déjà utilisé")); + } + $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + $estAdmin = $gateway->getEstAdminByEmail($_REQUEST['email']); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + $gateway->insert($Utilisateur); + $_SESSION['connected'] = 'true'; + $_SESSION['role'] = 'utilisateur'; + require ($rep.$vues['main']); + }catch (PDOException $e) + { + $error = "Erreur de connexion à la base de données."; + require ($rep.$vues['erreur']); + } + catch (Exception $e){ + require($rep.$vues['erreur']); + } + } + private function login(){ + global $rep, $vues, $sel, $error; + try { + $gateway = new UtilisateurGateway($this->con); + $Utilisateur = $gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($Utilisateur->getEmail() == null){ + $error = "Utilisateur non trouvé."; + throw new Exception("Utilisateur introuvable"); + } + $mdp = $gateway->getMdpByEmail($_REQUEST['email']); + if (password_verify($mdp, $_REQUEST['password'])){ + $error = "Mot de passe incorrect."; + throw new Exception("Mot de passe invalide"); + } + $estAdmin =$gateway->getEstAdminByEmail($_REQUEST['email']); + if ($estAdmin == true) { + $_SESSION['role'] = "admin"; + } + else{ + $_SESSION['role'] = "utilisateur"; + } - // $_SESSION['connected'] = 'true'; - // require ($rep.$vues['main']); - // }catch (Exception $e){ - // require($rep.$vues['erreur']); - // } - // } + $_SESSION['connected'] = 'true'; + require ($rep.$vues['main']); + }catch (Exception $e){ + require($rep.$vues['erreur']); + } + } private function goToPresentation() { global $rep, $vues, $error; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index dcd105d1..a7265fab 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -19,81 +19,81 @@ class UtilisateurGateway $this->con = $con; } - // public function insert(Utilisateur $utilisateur) : void{ - // $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; - // $this->con->executeQuery($query, array( - // ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), - // ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), - // ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), - // ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); - // } + public function insert(Utilisateur $utilisateur) : void{ + $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; + $this->con->executeQuery($query, array( + ':email' => array($utilisateur->getEmail(),PDO::PARAM_STR), + ':pseudo' => array($utilisateur->getPseudo(),PDO::PARAM_STR), + ':mdp' => array($utilisateur->getMdp(),PDO::PARAM_STR), + ':estAdmin' => array($utilisateur->getEstAdmin(),PDO::PARAM_BOOL))); + } - // public function delete(string $email) : void{ - // $query = "DELETE FROM utilisateur WHERE email=:email"; - // $this->con->executeQuery($query, array( - // ':email' => array($email ,PDO::PARAM_STR) - // )); - // } + public function delete(string $email) : void{ + $query = "DELETE FROM utilisateur WHERE email=:email"; + $this->con->executeQuery($query, array( + ':email' => array($email ,PDO::PARAM_STR) + )); + } - // public function getUtilisateurByEmail(string $email) : Utilisateur{ - // global $error; - // $query = "SELECT * FROM Utilisateur WHERE email=:email"; - // $this->con->executeQuery($query, array( - // ':email' => array($email,PDO::PARAM_STR) - // )); - // $results=$this->con->getResults(); - // foreach ($results as $row) { - // $email=$row['email']; - // $pseudo=$row['pseudo']; - // $mdp=$row['mdp']; - // $estAdmin=$row['estAdmin']; - // } - // if ($results == null){ - // return new Utilisateur("null", "null", "null", false); - // } - // return new Utilisateur($email, $pseudo, $mdp, $estAdmin); - // } + public function getUtilisateurByEmail(string $email) : Utilisateur{ + global $error; + $query = "SELECT * FROM Utilisateur WHERE email=:email"; + $this->con->executeQuery($query, array( + ':email' => array($email,PDO::PARAM_STR) + )); + $results=$this->con->getResults(); + foreach ($results as $row) { + $email=$row['email']; + $pseudo=$row['pseudo']; + $mdp=$row['mdp']; + $estAdmin=$row['estAdmin']; + } + if ($results == null){ + return new Utilisateur("null", "null", "null", false); + } + return new Utilisateur($email, $pseudo, $mdp, $estAdmin); + } - // public function getMdpByEmail(string $email) : string{ - // global $error; - // $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; - // $this->con->executeQuery($query, array( - // ':email' => array($email,PDO::PARAM_STR) - // )); - // $results=$this->con->getResults(); - // foreach ($results as $row) { - // $mdp=$row['mdp']; - // } - // if ($results == null){ - // $error = "Mot de passe non trouvé."; - // throw new Exception("Mots de passe Incorrect"); - // } - // return $mdp; - // } + public function getMdpByEmail(string $email) : string{ + global $error; + $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; + $this->con->executeQuery($query, array( + ':email' => array($email,PDO::PARAM_STR) + )); + $results=$this->con->getResults(); + foreach ($results as $row) { + $mdp=$row['mdp']; + } + if ($results == null){ + $error = "Mot de passe non trouvé."; + throw new Exception("Mots de passe Incorrect"); + } + return $mdp; + } - // public function getEstAdminByEmail(string $email) : bool{ - // global $error; - // $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; - // $this->con->executeQuery($query, array( - // ':email' => array($email,PDO::PARAM_STR) - // )); - // $results=$this->con->getResults(); - // foreach ($results as $row) { - // $estAdmin=$row['estAdmin']; - // } - // return $estAdmin; - // } + public function getEstAdminByEmail(string $email) : bool{ + global $error; + $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; + $this->con->executeQuery($query, array( + ':email' => array($email,PDO::PARAM_STR) + )); + $results=$this->con->getResults(); + foreach ($results as $row) { + $estAdmin=$row['estAdmin']; + } + return $estAdmin; + } - // public function showAll() : void{ - // $query = "SELECT * FROM Utilisateur"; - // $this->con->executeQuery($query); - // $results=$this->con->getResults(); - // foreach ($results as $row) { - // echo $row['email'] . '
'; - // echo $row['pseudo'] . '
'; - // echo $row['mdp'] . '
'; - // echo $row['estAdmin'] . '
'; - // } + public function showAll() : void{ + $query = "SELECT * FROM Utilisateur"; + $this->con->executeQuery($query); + $results=$this->con->getResults(); + foreach ($results as $row) { + echo $row['email'] . '
'; + echo $row['pseudo'] . '
'; + echo $row['mdp'] . '
'; + echo $row['estAdmin'] . '
'; + } - // } + } } \ No newline at end of file diff --git a/WEB/index.php b/WEB/index.php index 02769bd9..7a98214c 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -18,7 +18,7 @@ Autoload::charger(); // } echo "test"; -$db = new Connection(); +$db = new Connection($dsn); echo "test2"; // $control = new FrontController(); From 8c45e830829632d0953c44165ff5d8891e03cfa4 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:12:26 +0100 Subject: [PATCH 12/19] test --- WEB/Controller/UserController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 18fd13c6..b61a6b27 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,13 +2,13 @@ class UserController { - private Connection $con; + // private Connection $con; function __construct() { try{ echo "UserController"; global $dsn, $rep, $vues, $error; - $this->con=new Connection ($dsn); + // $this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { From 3099e1e68a0ca2f072fa172a5b150d723d78ef16 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:12:47 +0100 Subject: [PATCH 13/19] test --- WEB/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/index.php b/WEB/index.php index 7a98214c..6e187b71 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -20,7 +20,7 @@ Autoload::charger(); echo "test"; $db = new Connection($dsn); echo "test2"; -// $control = new FrontController(); +$control = new FrontController(); //session_regenerate_id(true); // session_unset(); From e201582945a4885b463396432a7c7e6d9f9146ac Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:13:59 +0100 Subject: [PATCH 14/19] test --- WEB/Controller/UserController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index b61a6b27..18fd13c6 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -2,13 +2,13 @@ class UserController { - // private Connection $con; + private Connection $con; function __construct() { try{ echo "UserController"; global $dsn, $rep, $vues, $error; - // $this->con=new Connection ($dsn); + $this->con=new Connection ($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { From e21197a0d0b5c7470dc099bd1998d7c8536fa7b8 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:17:07 +0100 Subject: [PATCH 15/19] Test --- WEB/Controller/FrontController.php | 4 ++-- WEB/Controller/UserController.php | 4 ++-- WEB/index.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 8870beaf..b230c9a3 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -1,7 +1,7 @@ getMessage(); require ($rep . $vues['erreur']); diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 18fd13c6..162e683c 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -4,11 +4,11 @@ class UserController { private Connection $con; - function __construct() { + function __construct($con) { try{ echo "UserController"; global $dsn, $rep, $vues, $error; - $this->con=new Connection ($dsn); + $this->con=$con; echo "USconection"; $action=$_REQUEST['action']; switch($action) { diff --git a/WEB/index.php b/WEB/index.php index 6e187b71..ac74911b 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -18,9 +18,9 @@ Autoload::charger(); // } echo "test"; -$db = new Connection($dsn); +$con = new Connection($dsn); echo "test2"; -$control = new FrontController(); +$control = new FrontController($con); //session_regenerate_id(true); // session_unset(); From d4b3947a2087dd0ecb617ec9ca90466be4d3bbe6 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:26:32 +0100 Subject: [PATCH 16/19] Test --- WEB/Controller/FrontController.php | 4 ++-- WEB/Controller/UserController.php | 4 ++-- WEB/Controller/UtilisateurGateway.php | 1 - WEB/index.php | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index b230c9a3..8870beaf 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -1,7 +1,7 @@ getMessage(); require ($rep . $vues['erreur']); diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 162e683c..a1fc969e 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -4,11 +4,11 @@ class UserController { private Connection $con; - function __construct($con) { + function __construct() { try{ echo "UserController"; global $dsn, $rep, $vues, $error; - $this->con=$con; + $this->con=new Connection($dsn); echo "USconection"; $action=$_REQUEST['action']; switch($action) { diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index a7265fab..cf92a54b 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -72,7 +72,6 @@ class UtilisateurGateway } public function getEstAdminByEmail(string $email) : bool{ - global $error; $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( ':email' => array($email,PDO::PARAM_STR) diff --git a/WEB/index.php b/WEB/index.php index ac74911b..6e187b71 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -18,9 +18,9 @@ Autoload::charger(); // } echo "test"; -$con = new Connection($dsn); +$db = new Connection($dsn); echo "test2"; -$control = new FrontController($con); +$control = new FrontController(); //session_regenerate_id(true); // session_unset(); From bb89c6db0883e7e9ffa49038a1c8b3f2eb5ed3a2 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:34:13 +0100 Subject: [PATCH 17/19] Maj chemin de Main.php --- WEB/View/src/pages/Main.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WEB/View/src/pages/Main.php b/WEB/View/src/pages/Main.php index 2355ce52..01faa449 100644 --- a/WEB/View/src/pages/Main.php +++ b/WEB/View/src/pages/Main.php @@ -16,7 +16,9 @@ integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous" /> - + " + ?> From 293098780176e0cf6a5d3bdbb0ba207715306dfd Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:39:03 +0100 Subject: [PATCH 18/19] Maj chemin --- WEB/View/src/pages/Main.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WEB/View/src/pages/Main.php b/WEB/View/src/pages/Main.php index 01faa449..1c0e20ee 100644 --- a/WEB/View/src/pages/Main.php +++ b/WEB/View/src/pages/Main.php @@ -16,9 +16,7 @@ integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous" /> - " - ?> + From f25546d940bbfebcd4b42c082f773efb741b14ac Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 28 Nov 2022 11:42:54 +0100 Subject: [PATCH 19/19] Maj chemin --- WEB/View/src/pages/Main.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WEB/View/src/pages/Main.php b/WEB/View/src/pages/Main.php index 1c0e20ee..2355ce52 100644 --- a/WEB/View/src/pages/Main.php +++ b/WEB/View/src/pages/Main.php @@ -16,7 +16,7 @@ integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous" /> - +