From 1fd508a3e22ba15d2b65efdba86615aaae3ec1b2 Mon Sep 17 00:00:00 2001 From: Pierre BALLANDRAS Date: Mon, 5 Dec 2022 11:54:19 +0100 Subject: [PATCH 01/13] Enigme de base print + var --- EnigmePython/Multi/ASCII.py | 1 + EnigmePython/Solo/premiere.py | 14 ++++++++++++++ WEB/View/src/JS/Affiche.js | 12 ++++++++++++ WEB/View/src/JS/Variable.js | 10 ++++++++++ 4 files changed, 37 insertions(+) create mode 100644 EnigmePython/Multi/ASCII.py create mode 100644 EnigmePython/Solo/premiere.py create mode 100644 WEB/View/src/JS/Affiche.js create mode 100644 WEB/View/src/JS/Variable.js diff --git a/EnigmePython/Multi/ASCII.py b/EnigmePython/Multi/ASCII.py new file mode 100644 index 00000000..053ed9b3 --- /dev/null +++ b/EnigmePython/Multi/ASCII.py @@ -0,0 +1 @@ +def ascii() \ No newline at end of file diff --git a/EnigmePython/Solo/premiere.py b/EnigmePython/Solo/premiere.py new file mode 100644 index 00000000..da3a2bfe --- /dev/null +++ b/EnigmePython/Solo/premiere.py @@ -0,0 +1,14 @@ +# Affiche Hello world ! + +print("Hello World !") + +# Declaration de variable + +num = 1 +string = "Oi" +liste=[num,string] + +print(liste) + + +# Utilisation de fonction \ No newline at end of file diff --git a/WEB/View/src/JS/Affiche.js b/WEB/View/src/JS/Affiche.js new file mode 100644 index 00000000..15a53b9e --- /dev/null +++ b/WEB/View/src/JS/Affiche.js @@ -0,0 +1,12 @@ +//~ Function that test the user code + +async function submit(){ + var test = editor.getValue(); + exec("print('Hello World !')", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file diff --git a/WEB/View/src/JS/Variable.js b/WEB/View/src/JS/Variable.js new file mode 100644 index 00000000..9dd0185c --- /dev/null +++ b/WEB/View/src/JS/Variable.js @@ -0,0 +1,10 @@ +async function submit(){ + var test = editor.getValue(); + exec("print([1,'Oui'])", "code"); + exec(test, "solution"); + result.innerHTML = "Test en cours..."; + await new Promise(r => setTimeout(r, 1500)); + check(); + } + + \ No newline at end of file From d6dcb15c7bc19f443c3236ca34a7b7a573748955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 5 Dec 2022 12:39:08 +0100 Subject: [PATCH 02/13] Changement du MVC --- WEB/Config/Autoload.php | 2 +- WEB/Config/Config.php | 2 +- WEB/Config/Connection.php | 39 +++--- WEB/Controller/EnigmeGateway.php | 9 +- WEB/Controller/FrontController.php | 1 - WEB/Controller/PartieGateway.php | 9 +- WEB/Controller/UserController.php | 168 +++----------------------- WEB/Controller/UtilisateurGateway.php | 10 +- WEB/Factory/PartieFactory.php | 2 - WEB/{Model => Metier}/Enigme.php | 0 WEB/{Model => Metier}/Partie.php | 0 WEB/{Model => Metier}/Utilisateur.php | 0 WEB/Model/Model.php | 146 ++++++++++++++++++++++ 13 files changed, 216 insertions(+), 172 deletions(-) rename WEB/{Model => Metier}/Enigme.php (100%) rename WEB/{Model => Metier}/Partie.php (100%) rename WEB/{Model => Metier}/Utilisateur.php (100%) create mode 100644 WEB/Model/Model.php diff --git a/WEB/Config/Autoload.php b/WEB/Config/Autoload.php index c67bf2f5..d745eebc 100644 --- a/WEB/Config/Autoload.php +++ b/WEB/Config/Autoload.php @@ -34,7 +34,7 @@ class Autoload { global $rep; $filename = $class.'.php'; - $dir =array('Model/','./','Config/','Controller/'); + $dir =array('Model/','./','Config/','Controller/','Metier/', 'Factory/'); foreach ($dir as $d){ $file=$rep.$d.$filename; //echo $file; diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 9853af16..0f773a6a 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -23,7 +23,7 @@ $sel = "JeSuisUnSeldeHashageEtJeSuisUniqueEtTresSecuriseEtJeSuisTresLong"; //Page $vues['main'] = 'View/src/pages/Main.php'; $vues['presentation'] = 'View/src/pages/Presentation.html'; -$vues['login'] = '../View/src/pages/LogSign/Login.php'; +$vues['login'] = '/View/src/pages/LogSign/Login.php'; $vues['signUp'] = 'View/src/pages/LogSign/SignUp.php'; $vues['enigme'] = 'View/src/pages/Palindrome.html'; diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 987a2594..936fdcf3 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -19,26 +19,37 @@ class Connection extends SQLite3 { - private $stmt; - private $result; - function __construct($dsn) + 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(); + if ($this->result == false) { + return false; + } else { + return true; + } + } - public function getResults(): array { - return $this->result->fetchArray(); - } + public function getResults(): array + { + var_dump($this->result->fetchArray(SQLITE3_ASSOC)); + if ($this->result->fetchArray(SQLITE3_ASSOC) == false) { + return array(); + } else { + return $this->result->fetchArray(SQLITE3_ASSOC); + } + } } // class Connection extends SQLite3{ diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 68679e16..bd13b6e0 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -7,9 +7,16 @@ class EnigmeGateway * @param Connection $con */ - public function __construct(Connection $con) + public function __construct() { + global $dsn, $rep, $vues, $error; + try{ + $con = new Connection($dsn); $this->con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index 8870beaf..ebe2bc55 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -7,7 +7,6 @@ class FrontController session_start(); // $role=$_SESSION['role']; // $action=$_REQUEST['action']; - echo "frontController"; try { new UserController(); } catch (Exception $e) { diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index 05a7c8f8..7fb6498f 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -6,9 +6,16 @@ class PartieGateway /** * @param Connection $con */ - public function __construct(Connection $con) + public function __construct() { + global $dsn, $rep, $vues, $error; + try{ + $con = new Connection($dsn); $this->con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 31f41663..9ac080a6 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -6,177 +6,47 @@ class UserController { private Connection $con; - function __construct() { - try{ - echo "UserController"; + function __construct() + { + try { global $dsn, $rep, $vues, $error; - $this->con=new Connection($dsn); - echo "USconection"; - $action=$_REQUEST['action']; - switch($action) { + $model = new Model(); + $action = $_REQUEST['action']; + switch ($action) { case NULL: - $this->goToHome(); + $model->goToHome(); break; case "signUp": - $this->signUp(); + $model->signUp(); break; case "login": - $this->login(); + $model->login(); break; case "goToPresentation": - $this->goToPresentation(); + $model->goToPresentation(); break; case "goToHome": - $this->goToHome(); + $model->goToHome(); break; case "goToLogin": - $this->goToLogin(); + $model->goToLogin(); break; case "goToSignUp": - $this->goToSignUp(); + $model->goToSignUp(); break; case "goToEnigme": - $this->goToEnigme(); + $model->goToEnigme(); break; case "goToQueue": - $this->goToQueue(); + $model->goToQueue(); break; } - } catch (PDOException $e) - { + } catch (PDOException $e) { $error = $e->getMessage(); - require ($rep.$vues['erreur']); - }catch (Exception $e2) - { + require($rep . $vues['erreur']); + } catch (Exception $e2) { $error = $e2->getMessage(); - require ($rep.$vues['erreur']); - } - } - - 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->getEmail() != "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']); - } - } - - 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; - try { - require ($rep.$vues['main']); - }catch (Exception $e){ - $error = "404"; - require($rep.$vues['erreur']); - } - } - - private function goToLogin() { - global $rep, $vues, $error; - try { - require ($rep.$vues['login']); - }catch (Exception $e){ - $error = "404"; - require($rep.$vues['erreur']); - } - } - - private function goToSignUp() { - global $rep, $vues, $error; - try { - require ($rep.$vues['signUp']); - }catch (Exception $e){ - $error = "404"; - require($rep.$vues['erreur']); - } - } - - private function goToEnigme() { - global $rep, $vues, $error; - try { - require ($rep.$vues['enigme']); - }catch (Exception $e){ - $error = "404"; - require($rep.$vues['erreur']); - } - } - - private function goToQueue() { - global $rep, $vues, $error; - try { - require ($rep.$vues['Queue']); - }catch (Exception $e){ - $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } } \ No newline at end of file diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index e9c2ec01..9306480c 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -1,5 +1,4 @@ con = $con; + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } } /** diff --git a/WEB/Factory/PartieFactory.php b/WEB/Factory/PartieFactory.php index 58f3bb53..de23d7c0 100644 --- a/WEB/Factory/PartieFactory.php +++ b/WEB/Factory/PartieFactory.php @@ -1,6 +1,4 @@ enigme_gateway = new EnigmeGateway(); + $this->partie_gateway = new PartieGateway(); + $this->utilisateur_gateway = new UtilisateurGateway(); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $view['erreur']); + } + } + + public function signUp() { + global $rep, $vues, $sel, $error; + try { + $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 = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($j->getEmail() != "null") { + $error = "Email déjà utilisé."; + throw (new Exception("Email déjà utilisé")); + } + $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + $estAdmin = $this->utilisateur_gateway->getEstAdminByEmail($_REQUEST['email']); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + $this->utilisateur_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']); + } + } + public function login(){ + global $rep, $vues, $sel, $error; + try { + $Utilisateur = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); + if ($Utilisateur->getEmail() == "null") { + $error = "Utilisateur non trouvé."; + throw new Exception("Utilisateur introuvable"); + } + $mdp = $this->utilisateur_gateway->getMdpByEmail($_REQUEST['email']); + if (password_verify($mdp, $_REQUEST['password'])){ + $error = "Mot de passe incorrect."; + throw new Exception("Mot de passe invalide"); + } + $estAdmin = $this->utilisateur_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']); + } + } + + public function goToPresentation() { + global $rep, $vues, $error; + try { + require ($rep.$vues['presentation']); + }catch (Exception $e){ + $error = "Erreur Inconnue"; + require($rep.$vues['erreur']); + } + } + + public function goToHome() { + global $rep, $vues, $error; + try { + require ($rep.$vues['main']); + }catch (Exception $e){ + $error = "404"; + require($rep.$vues['erreur']); + } + } + + public function goToLogin() { + global $rep, $vues, $error; + try { + require ($rep.$vues['login']); + }catch (Exception $e){ + $error = "404"; + require($rep.$vues['erreur']); + } + } + + public function goToSignUp() { + global $rep, $vues, $error; + try { + require ($rep.$vues['signUp']); + }catch (Exception $e){ + $error = "404"; + require($rep.$vues['erreur']); + } + } + + public function goToEnigme() { + global $rep, $vues, $error; + try { + require ($rep.$vues['enigme']); + }catch (Exception $e){ + $error = "404"; + require($rep.$vues['erreur']); + } + } + + public function goToQueue() { + global $rep, $vues, $error; + try { + require ($rep.$vues['Queue']); + }catch (Exception $e){ + $error = "404"; + require($rep.$vues['erreur']); + } + } +} \ No newline at end of file From 3859d10cee5a9152261a6e1b7ec18c8f32a5fc20 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 5 Dec 2022 13:07:18 +0100 Subject: [PATCH 03/13] =?UTF-8?q?Correction=20de=20l'insertion=20d'utilisa?= =?UTF-8?q?teur=20dans=20la=20base=20de=20donn=C3=A9es=20sqlite3=20effectu?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/UtilisateurGateway.php | 18 +++++++++--------- WEB/Model/Model.php | 4 ++-- WEB/Model/scripted.db | Bin 53248 -> 53248 bytes 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 9306480c..4fd5943a 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -26,18 +26,18 @@ class UtilisateurGateway } public function insert(Utilisateur $utilisateur) : void{ - $query = "INSERT INTO Utilisateur VALUE (:email,:pseudo,:mdp,:estAdmin)"; + $query = "INSERT INTO Utilisateur VALUES (: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))); + ':email' => array($utilisateur->getEmail(),SQLITE3_TEXT), + ':pseudo' => array($utilisateur->getPseudo(),SQLITE3_TEXT), + ':mdp' => array($utilisateur->getMdp(),SQLITE3_TEXT), + ':estAdmin' => array($utilisateur->getEstAdmin(),SQLITE3_INTEGER))); } public function delete(string $email) : void{ $query = "DELETE FROM utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email ,PDO::PARAM_STR) + ':email' => array($email ,SQLITE3_TEXT) )); } @@ -45,7 +45,7 @@ class UtilisateurGateway global $error; $query = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -64,7 +64,7 @@ class UtilisateurGateway global $error; $query = "SELECT mdp FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); foreach ($results as $row) { @@ -80,7 +80,7 @@ class UtilisateurGateway public function getEstAdminByEmail(string $email) : bool{ $query = "SELECT estAdmin FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR) + ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); foreach ($results as $row) { diff --git a/WEB/Model/Model.php b/WEB/Model/Model.php index 5aa983ef..8dadab10 100644 --- a/WEB/Model/Model.php +++ b/WEB/Model/Model.php @@ -41,8 +41,7 @@ class Model throw (new Exception("Email déjà utilisé")); } $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); - $estAdmin = $this->utilisateur_gateway->getEstAdminByEmail($_REQUEST['email']); - $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, $estAdmin); + $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false); $this->utilisateur_gateway->insert($Utilisateur); $_SESSION['connected'] = 'true'; $_SESSION['role'] = 'utilisateur'; @@ -53,6 +52,7 @@ class Model require ($rep.$vues['erreur']); } catch (Exception $e){ + $error = $e->getMessage(); require($rep.$vues['erreur']); } } diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index aae746736ea05245fd8b01cf0ee4545494dd7a18..ec4ca301f94a14ee1b36fbfd474d5bd789da0278 100644 GIT binary patch delta 184 zcmZozz}&Ead4e<}_e2?IR&EA8`}NUY=!MS!s5Zeon5xn@@>} zbD&;&g;A1+e@K~cNN8ncNm-DSS*eecevV;Dk!hM Date: Mon, 5 Dec 2022 13:13:24 +0100 Subject: [PATCH 04/13] =?UTF-8?q?Correction=20des=20liens=20de=20la=20vue?= =?UTF-8?q?=20de=20pr=C3=A9sentation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/View/src/pages/Presentation.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/WEB/View/src/pages/Presentation.html b/WEB/View/src/pages/Presentation.html index 39f8cbbd..d5e6e10f 100644 --- a/WEB/View/src/pages/Presentation.html +++ b/WEB/View/src/pages/Presentation.html @@ -10,7 +10,7 @@ integrity="sha384-r4NyP46KrjDleawBgD5tp8Y7UzmLA05oM1iAEQ17CSuDqnUK2+k9luXQOfXJCJ4I" crossorigin="anonymous" /> - + - + - +
@@ -81,7 +81,7 @@
Logo Date: Mon, 5 Dec 2022 14:23:27 +0100 Subject: [PATCH 05/13] Correction bug bd --- WEB/Config/Connection.php | 8 +++++--- WEB/Controller/UtilisateurGateway.php | 16 ++++++---------- WEB/Model/scripted.db | Bin 53248 -> 53248 bytes 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index 936fdcf3..d8ad3faf 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -35,19 +35,21 @@ class Connection extends SQLite3 } $this->result = $this->stmt->execute(); if ($this->result == false) { + $this->result->finalize(); return false; } else { + $this->result->finalize(); return true; } } public function getResults(): array { - var_dump($this->result->fetchArray(SQLITE3_ASSOC)); - if ($this->result->fetchArray(SQLITE3_ASSOC) == false) { + $tmp = $this->result->fetchArray(SQLITE3_ASSOC); + if ($tmp == false) { return array(); } else { - return $this->result->fetchArray(SQLITE3_ASSOC); + return $tmp; } } } diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 4fd5943a..954bc06b 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -48,16 +48,14 @@ class UtilisateurGateway ':email' => array($email,SQLITE3_TEXT) )); $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,false); + $email=$results['email']; + $pseudo=$results['pseudo']; + $mdp=$results['mdp']; + $estAdmin=$results['estAdmin']; + return new Utilisateur($email, $pseudo, $mdp, $estAdmin); } public function getMdpByEmail(string $email) : string{ @@ -83,9 +81,7 @@ class UtilisateurGateway ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); - foreach ($results as $row) { - $estAdmin=$row['estAdmin']; - } + $estAdmin=$results['estAdmin']; return $estAdmin; } diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index ec4ca301f94a14ee1b36fbfd474d5bd789da0278..34dc7d52b9de0eeb6e2d70f0d1e12798676dd22f 100644 GIT binary patch delta 438 zcmZozz}&Ead4e<}|3n#QM*fWn3;B8Z=P@wzRWb0p@ZIC9+AJuL!&jfg!e*)1$jafD zpQ`8X806>a8sv~#QmR*)oT!&pl$W2LSd^EUT4bnVRHStl-<&~crlob)?;+&FI6`11Vnp+VOQB_`IYGPb$Y8srIZ|a@G%w`L+BM)c?)I7bs zbcgiZ#LW5}z2y8{3~QWBD?E)I!~Cj(Jqyc&D>E$0{qlWN3qnlw{gXmH(_K=N3Jgob zQZwBP4YGox+)O;e%|rAenAmhBf!3sy7UbuZfQ<*64&g&RVC0@rln6cU+e?&X%G zm7H1TR_W`nmlBX@V&I(?YGD~5|L9z>qX~k$e&tGyi4= t{>}X7_#bZ;R9MRIE5&Tdh&||7M3{9M(VfC1!)(ilB^bc&WL{*j003?6iFW`1 delta 90 zcmZozz}&Ead4e<}_e2?IM(&LX3;8)27#JA&=P~fl+bpOsg`XvXk Date: Mon, 5 Dec 2022 14:31:40 +0100 Subject: [PATCH 06/13] ajout d'un sel de hashage --- WEB/Model/Model.php | 99 ++++++++++++++++++++++-------------------- WEB/Model/scripted.db | Bin 53248 -> 53248 bytes WEB/index.php | 14 ------ 3 files changed, 52 insertions(+), 61 deletions(-) diff --git a/WEB/Model/Model.php b/WEB/Model/Model.php index 8dadab10..a58a4cc4 100644 --- a/WEB/Model/Model.php +++ b/WEB/Model/Model.php @@ -19,44 +19,44 @@ class Model } } - public function signUp() { + public function signUp() + { global $rep, $vues, $sel, $error; try { $validation = new Validation(); - if (! $validation->ValidateEmail($_REQUEST['email'])) { + if (!$validation->ValidateEmail($_REQUEST['email'])) { $error = "Email invalides."; throw (new Exception("Email non valide")); } - if(! $validation->ValidateUsername($_REQUEST['username'])){ + 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")); + throw (new Exception("Pseudo non valide")); } - if(! $validation->ValidatePassword($_REQUEST['password'])){ + 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")); + throw (new Exception("Mot de passe non valide")); } $j = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); if ($j->getEmail() != "null") { $error = "Email déjà utilisé."; throw (new Exception("Email déjà utilisé")); } - $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); + $password = password_hash($_REQUEST['password'] . $sel, PASSWORD_DEFAULT); $Utilisateur = new Utilisateur($_REQUEST['email'], $_REQUEST['username'], $password, false); $this->utilisateur_gateway->insert($Utilisateur); $_SESSION['connected'] = 'true'; $_SESSION['role'] = 'utilisateur'; - require ($rep.$vues['main']); - }catch (PDOException $e) - { + require($rep . $vues['main']); + } catch (PDOException $e) { $error = "Erreur de connexion à la base de données."; - require ($rep.$vues['erreur']); - } - catch (Exception $e){ - $error = $e->getMessage(); - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); } } - public function login(){ + public function login() + { global $rep, $vues, $sel, $error; try { $Utilisateur = $this->utilisateur_gateway->getUtilisateurByEmail($_REQUEST['email']); @@ -65,82 +65,87 @@ class Model throw new Exception("Utilisateur introuvable"); } $mdp = $this->utilisateur_gateway->getMdpByEmail($_REQUEST['email']); - if (password_verify($mdp, $_REQUEST['password'])){ + if (password_verify($mdp, $_REQUEST['password'] . $sel)) { $error = "Mot de passe incorrect."; throw new Exception("Mot de passe invalide"); } $estAdmin = $this->utilisateur_gateway->getEstAdminByEmail($_REQUEST['email']); if ($estAdmin == true) { $_SESSION['role'] = "admin"; - } - else{ + } 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']); } } - public function goToPresentation() { + public function goToPresentation() + { global $rep, $vues, $error; try { - require ($rep.$vues['presentation']); - }catch (Exception $e){ + require($rep . $vues['presentation']); + } catch (Exception $e) { $error = "Erreur Inconnue"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - public function goToHome() { + public function goToHome() + { global $rep, $vues, $error; try { - require ($rep.$vues['main']); - }catch (Exception $e){ + require($rep . $vues['main']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - public function goToLogin() { + public function goToLogin() + { global $rep, $vues, $error; try { - require ($rep.$vues['login']); - }catch (Exception $e){ + require($rep . $vues['login']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - public function goToSignUp() { + public function goToSignUp() + { global $rep, $vues, $error; try { - require ($rep.$vues['signUp']); - }catch (Exception $e){ + require($rep . $vues['signUp']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - public function goToEnigme() { + public function goToEnigme() + { global $rep, $vues, $error; try { - require ($rep.$vues['enigme']); - }catch (Exception $e){ + require($rep . $vues['enigme']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } - public function goToQueue() { + public function goToQueue() + { global $rep, $vues, $error; try { - require ($rep.$vues['Queue']); - }catch (Exception $e){ + require($rep . $vues['Queue']); + } catch (Exception $e) { $error = "404"; - require($rep.$vues['erreur']); + require($rep . $vues['erreur']); } } } \ No newline at end of file diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index 34dc7d52b9de0eeb6e2d70f0d1e12798676dd22f..3ab47f7796e837594fd90fa0cfdd45b2e814a8f4 100644 GIT binary patch delta 256 zcmZozz}&Ead4e>f&_o$$Mxl)f3;B5&7#JA&moe}!~{xg-{#qCJy6>N)Y!BT!-{>Kc`e)*|-?v6ozo~}U-sU@X)rOAnUX+PI>?U delta 256 zcmZozz}&Ead4e<}|3n#QM*fWn3;B8Z=P@wzRWb0p@ZIC9+AOG$!^e`u!e%+SPA-8Z zg_+HE@*}w1hr{sTn1edTB*j`BkZDDn^wm zh6XCWiRpTImU(5R*-`pAx&CfGB__^+dg&ELNgn0`f_&4*PUTJb7&^i_o vW?jaV(t`ZF5{LBM#LOJMprepare("INSERT INTO Utilisateur VALUES (:email, :password, :pseudo, :admin)"); -// $stm->bindValue(':email', "e",SQLITE3_TEXT); -// $stm->bindValue(':password', "e" ,SQLITE3_TEXT); -// $stm->bindValue(':pseudo', "e", SQLITE3_TEXT); -// $stm->bindValue(':admin', 0, SQLITE3_INTEGER); -// $stm->execute(); - -// $res = $db->query('SELECT * FROM Utilisateur'); -// Select all the users in the database -// while ($row = $res->fetchArray()) { -// echo $row['email'] . " " . $row['password'] . " " . $row['pseudo'] . " " . $row['admin'] . " "; -// } - $control = new FrontController(); //session_regenerate_id(true); From 259eeb31a90a6b7778408ef8b303d490e52f375e Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 5 Dec 2022 14:44:46 +0100 Subject: [PATCH 07/13] =?UTF-8?q?Ajout=20de=20la=20fonction=20de=20d=C3=A9?= =?UTF-8?q?connexion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Model/Model.php | 8 ++++++++ WEB/Model/scripted.db | Bin 53248 -> 53248 bytes 2 files changed, 8 insertions(+) diff --git a/WEB/Model/Model.php b/WEB/Model/Model.php index a58a4cc4..d0712ad9 100644 --- a/WEB/Model/Model.php +++ b/WEB/Model/Model.php @@ -148,4 +148,12 @@ class Model require($rep . $vues['erreur']); } } + + public function logout() + { + session_unset(); + session_destroy(); + $_SESSION = null; + $this->goToHome(); + } } \ No newline at end of file diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index 3ab47f7796e837594fd90fa0cfdd45b2e814a8f4..5ee8fe2053fc77ffcf0f367052a5b486521ae290 100644 GIT binary patch delta 171 zcmZozz}&Ead4e>f@I)DBM&XSKOZd5%_=6evm+=SlRc#hj$l;q@C3iD8kcmxQu#uG` zD?cMK&mlK4GeuX)DKX7Gxg^g&Ju!9iGWj^5UAGwc-|*k!f4o`HU@8CP&HCy>g3RiS NDE2UIexon4005RbHw6Fy delta 171 zcmZozz}&Ead4e>f&_o$$Mxl)fOZd4M`Ij;9FXOA?tJ*B6ki$2*O73QGdTwH7j$U$p zZc1rEeqM=+QKgEZfr^oPMp3SJqESd>qPdq_QgUXQTcxkRUP?fsiGg=osD)*aMWS!0 zOKFKmQBYD?s-c;OrAsaY14EK{BP++`W%6-AyWTMHzu`Z}|9G>Y!BYOooAuR&U{)~! RRm$e&r|P9|exon40007NHU Date: Mon, 5 Dec 2022 15:30:16 +0100 Subject: [PATCH 08/13] Mise en place du FrontController --- WEB/Config/Connection.php | 9 +-- WEB/Controller/FrontController.php | 31 +++++++++-- WEB/Controller/UserController.php | 14 ++--- WEB/Controller/VisitorController.php | 54 ++++++++++++++++++ WEB/Model/UserModel.php | 64 ++++++++++++++++++++++ WEB/Model/{Model.php => VisitorModel.php} | 7 +-- WEB/Model/scripted.db | Bin 53248 -> 53248 bytes WEB/View/src/pages/Main.php | 2 +- WEB/{Model => }/bd.sql | 0 WEB/index.php | 6 +- 10 files changed, 156 insertions(+), 31 deletions(-) create mode 100644 WEB/Controller/VisitorController.php create mode 100644 WEB/Model/UserModel.php rename WEB/Model/{Model.php => VisitorModel.php} (96%) rename WEB/{Model => }/bd.sql (100%) diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index d8ad3faf..da3a86e8 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -52,11 +52,4 @@ class Connection extends SQLite3 return $tmp; } } -} - -// class Connection extends SQLite3{ -// function __construct() -// { -// $this->open("./Model/scripted.db"); -// } -// } \ No newline at end of file +} \ No newline at end of file diff --git a/WEB/Controller/FrontController.php b/WEB/Controller/FrontController.php index ebe2bc55..36691fae 100644 --- a/WEB/Controller/FrontController.php +++ b/WEB/Controller/FrontController.php @@ -3,15 +3,34 @@ class FrontController { function __construct() { - global $rep, $vues, $error; - session_start(); - // $role=$_SESSION['role']; - // $action=$_REQUEST['action']; try { - new UserController(); + global $error, $view, $rep; + session_start(); + // Check role permissions + if (isset($_SESSION['role'])) { + $role = $_SESSION['role']; + } else { + $role = "visitor"; + } + + // Check if action exists + $action = $_REQUEST['action']; + if ($role == "user") { + if ($action == NULL) { + new UserController(); + } + else if (method_exists('UserModel', $action) == false) { + $error = "Action non valide " . $action; + require($rep . $view['erreur']); + } else { + new UserController(); + } + } else { + new VisitorController(); + } } catch (Exception $e) { $error = $e->getMessage(); - require ($rep . $vues['erreur']); + require($rep . $view['erreur']); } } } \ No newline at end of file diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 9ac080a6..c1676fa4 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -1,7 +1,5 @@ goToHome(); break; - case "goToLogin": - $model->goToLogin(); - break; - case "goToSignUp": - $model->goToSignUp(); - break; case "goToEnigme": $model->goToEnigme(); break; case "goToQueue": $model->goToQueue(); break; + default: + $error = "Action non valide"; + require($rep . $vues['erreur']); + break; } } catch (PDOException $e) { $error = $e->getMessage(); diff --git a/WEB/Controller/VisitorController.php b/WEB/Controller/VisitorController.php new file mode 100644 index 00000000..a171c593 --- /dev/null +++ b/WEB/Controller/VisitorController.php @@ -0,0 +1,54 @@ +goToHome(); + break; + case "signUp": + $model->signUp(); + break; + case "login": + $model->login(); + break; + case "goToPresentation": + $model->goToPresentation(); + break; + case "goToHome": + $model->goToHome(); + break; + case "goToLogin": + $model->goToLogin(); + break; + case "goToSignUp": + $model->goToSignUp(); + break; + case "goToEnigme": + $model->goToEnigme(); + break; + case "goToQueue": + $model->goToQueue(); + break; + default: + $error = "Action non valide"; + require($rep . $vues['erreur']); + break; + } + } catch (PDOException $e) { + $error = $e->getMessage(); + require($rep . $vues['erreur']); + } catch (Exception $e2) { + $error = $e2->getMessage(); + require($rep . $vues['erreur']); + } + } +} \ No newline at end of file diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php new file mode 100644 index 00000000..db2e308c --- /dev/null +++ b/WEB/Model/UserModel.php @@ -0,0 +1,64 @@ +enigme_gateway = new EnigmeGateway(); + $this->partie_gateway = new PartieGateway(); + $this->utilisateur_gateway = new UtilisateurGateway(); + } catch (Exception $e) { + $error = $e->getMessage(); + require($rep . $view['erreur']); + } + } + + public function goToPresentation() + { + global $rep, $vues, $error; + try { + require($rep . $vues['presentation']); + } catch (Exception $e) { + $error = "Erreur Inconnue"; + require($rep . $vues['erreur']); + } + } + + public function goToHome() + { + global $rep, $vues, $error; + try { + require($rep . $vues['main']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + public function goToEnigme() + { + global $rep, $vues, $error; + try { + require($rep . $vues['enigme']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } + + public function goToQueue() + { + global $rep, $vues, $error; + try { + require($rep . $vues['Queue']); + } catch (Exception $e) { + $error = "404"; + require($rep . $vues['erreur']); + } + } +} \ No newline at end of file diff --git a/WEB/Model/Model.php b/WEB/Model/VisitorModel.php similarity index 96% rename from WEB/Model/Model.php rename to WEB/Model/VisitorModel.php index a58a4cc4..f975ed46 100644 --- a/WEB/Model/Model.php +++ b/WEB/Model/VisitorModel.php @@ -1,5 +1,5 @@ utilisateur_gateway->insert($Utilisateur); - $_SESSION['connected'] = 'true'; - $_SESSION['role'] = 'utilisateur'; + $_SESSION['role'] = 'user'; require($rep . $vues['main']); } catch (PDOException $e) { $error = "Erreur de connexion à la base de données."; @@ -73,7 +72,7 @@ class Model if ($estAdmin == true) { $_SESSION['role'] = "admin"; } else { - $_SESSION['role'] = "utilisateur"; + $_SESSION['role'] = "user"; } $_SESSION['connected'] = 'true'; diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index 3ab47f7796e837594fd90fa0cfdd45b2e814a8f4..ce905aeb001b4057c8b7ba77e8381eb78ce603b7 100644 GIT binary patch delta 150 zcmZozz}&Ead4e>f$V3@uRuKlhWQL6?%lKLNo%pIY3o7LBO|FtV!NS16kTSVWPTSO| z(kCi6+$_?gsw6M8%E>I)+bKQAKc&Q1zo0xc$IHXTJ1x^Q*~QR3Bg#9#+&DllCr>YU z@-q2U<~RJ0Hwzjp<)6G+Urrimp0rf&_o$$Rv`vG`n6cU+e?&X%0oLS~p>FckT5|C(O z;GGs~VHsqR=o{)%TH;X@loXa~Xy#$*k_$9BNgQbM Date: Mon, 5 Dec 2022 15:36:05 +0100 Subject: [PATCH 09/13] Correction de la classe connection --- WEB/Config/Connection.php | 14 +++++++---- WEB/Controller/EnigmeGateway.php | 13 +++++++++++ WEB/Controller/UtilisateurGateway.php | 11 +++++---- WEB/Model/Model.php | 32 +++++++++++++++++++++++++- WEB/Model/scripted.db | Bin 53248 -> 53248 bytes WEB/index.php | 6 ++--- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/WEB/Config/Connection.php b/WEB/Config/Connection.php index d8ad3faf..be9b541f 100644 --- a/WEB/Config/Connection.php +++ b/WEB/Config/Connection.php @@ -45,12 +45,16 @@ class Connection extends SQLite3 public function getResults(): array { - $tmp = $this->result->fetchArray(SQLITE3_ASSOC); - if ($tmp == false) { - return array(); - } else { - return $tmp; + $resultArray = array(); + $multiArray = array(); + while($resultArray != false){ + $resultArray = $this->result->fetchArray(SQLITE3_ASSOC); //read next row + array_push($multiArray, $resultArray); //insert all rows to $multiArray } + if ($multiArray == NULL) + return array(); + else + return $multiArray; } } diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index bd13b6e0..8379835d 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -51,6 +51,19 @@ class EnigmeGateway )); } + public function findMultiEnigma() : array + { + $query = "SELECT * FROM Enigme + WHERE points IS NOT NULL OR points != 0"; + $this->con->executeQuery($query); + $results = $this->con->getResults(); + return $results; + } + + public function findSoloEnigma(){ + + } + public function findById(string $idEnigme) : array { $query="SELECT * FROM Enigme WHERE idEnigme =:idEnigme"; diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 954bc06b..136ebc06 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -51,10 +51,13 @@ class UtilisateurGateway if ($results == null){ return new Utilisateur("null", "null", "null", false); } - $email=$results['email']; - $pseudo=$results['pseudo']; - $mdp=$results['mdp']; - $estAdmin=$results['estAdmin']; + foreach($results as $row) + { + $email = $row['email']; + $pseudo=$row['pseudo']; + $mdp = $row['mdp']; + $estAdmin = $row['estAdmin']; + } return new Utilisateur($email, $pseudo, $mdp, $estAdmin); } diff --git a/WEB/Model/Model.php b/WEB/Model/Model.php index d0712ad9..29c1d764 100644 --- a/WEB/Model/Model.php +++ b/WEB/Model/Model.php @@ -148,7 +148,7 @@ class Model require($rep . $vues['erreur']); } } - + public function logout() { session_unset(); @@ -156,4 +156,34 @@ class Model $_SESSION = null; $this->goToHome(); } + public function addEnigme() + { + global $rep, $vues, $error; + try{ + $solo = $_REQUEST['solo']; + if($solo) + $enigme = new Enigme($_REQUEST['enonce'],$_REQUEST['aide'],$_REQUEST['rappel'],$_REQUEST['solution'],$_REQUEST['test'],0,0); + else + $enigme = new Enigme($_REQUEST['enonce'],$_REQUEST['aide'],$_REQUEST['rappel'],$_REQUEST['solution'],$_REQUEST['test'],$_REQUEST['tempsDeResolution'],$_REQUEST['points']); + $this->enigme_gateway->insert($enigme); + } + catch(Exception $e) { + $error = "500"; + require($rep . $vues['erreur']); + } + } + + public function deleteEnigme() + { + global $rep, $vues, $error; + try{ + $this->enigme_gateway->delete($_REQUEST['id']); + } + catch(Exception $e) { + $error = "500"; + require($rep . $vues['erreur']); + } + } + + public function } \ No newline at end of file diff --git a/WEB/Model/scripted.db b/WEB/Model/scripted.db index 5ee8fe2053fc77ffcf0f367052a5b486521ae290..46151e5f2b7d567a0be730aa5b0aa03ce9bb6c20 100644 GIT binary patch delta 275 zcmZozz}&Ead4e>f=tLQ3M$wH4OZa(M_|`G-FXIp9XX0D8Sx_O1Z*rBKNqrCto2qCd zD@Rs-cA`UWVrGtBS`mn?VpOSOXrPkfofeo;Y;Kimxxr2X;*m{l2(ozKG0tPB!>+0DH9mcH5o08`ym5C8xG delta 271 zcmZozz}&Ead4e>f@I)DBM&XSKOZd5%_=6evm+=SlRc#hj$l;q@C1+CaY3PwsUTk1$ zS?XtD=;f848k7|g=Hi@^RTY@xun{VpPKaU|zv5}P{FF#c; zJ+UY+Gqp%BFWn(MH!(9uFF8LqFCQvusA5#9VrZb^WLn{A>=@=(73^799$cAWQSO)T zn_3WJs_&l^>Zz9QlA2UtSQ?g^>0W4%6&&Se;t_5hqQ}6%utySTO-gA&eqM>gimxxr2T--aCZ#y^K=bzNG&PVD@{(+ODkdlYBz#vP2YS= HUu^*ZM?+TJ diff --git a/WEB/index.php b/WEB/index.php index 1b8647e6..468267f3 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -6,8 +6,8 @@ Autoload::charger(); $control = new FrontController(); //session_regenerate_id(true); -// session_unset(); -// session_destroy(); -// $_SESSION = null; +session_unset(); +session_destroy(); +$_SESSION = null; //https://a-pellegrini.developpez.com/temp/tutoriels/php/security/session/#III.2 \ No newline at end of file From a4919ec288543d894e51024a1f5d21eea0312ee9 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 5 Dec 2022 15:40:01 +0100 Subject: [PATCH 10/13] Version qui marche --- WEB/Model/VisitorModel.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/WEB/Model/VisitorModel.php b/WEB/Model/VisitorModel.php index cfa123a4..6c864c82 100644 --- a/WEB/Model/VisitorModel.php +++ b/WEB/Model/VisitorModel.php @@ -183,6 +183,4 @@ class VisitorModel require($rep . $vues['erreur']); } } - - public function } \ No newline at end of file From 73fe02d318c4e09bd9a85d85eb456d750fd2d4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Garnier?= Date: Mon, 5 Dec 2022 15:46:40 +0100 Subject: [PATCH 11/13] =?UTF-8?q?Maj=20FrontController=20+=20function=20de?= =?UTF-8?q?=20d=C3=A9connexion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Controller/UserController.php | 9 ++---- WEB/Controller/VisitorController.php | 9 ------ WEB/Model/UserModel.php | 6 ++++ WEB/Model/VisitorModel.php | 41 ---------------------------- WEB/index.php | 6 ++-- 5 files changed, 12 insertions(+), 59 deletions(-) diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index c1676fa4..1881b51c 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -14,12 +14,6 @@ class UserController case NULL: $model->goToHome(); break; - case "signUp": - $model->signUp(); - break; - case "login": - $model->login(); - break; case "goToPresentation": $model->goToPresentation(); break; @@ -32,6 +26,9 @@ class UserController case "goToQueue": $model->goToQueue(); break; + case "logout": + $model->logout(); + break; default: $error = "Action non valide"; require($rep . $vues['erreur']); diff --git a/WEB/Controller/VisitorController.php b/WEB/Controller/VisitorController.php index a171c593..ec9d57bb 100644 --- a/WEB/Controller/VisitorController.php +++ b/WEB/Controller/VisitorController.php @@ -20,9 +20,6 @@ class VisitorController case "login": $model->login(); break; - case "goToPresentation": - $model->goToPresentation(); - break; case "goToHome": $model->goToHome(); break; @@ -32,12 +29,6 @@ class VisitorController case "goToSignUp": $model->goToSignUp(); break; - case "goToEnigme": - $model->goToEnigme(); - break; - case "goToQueue": - $model->goToQueue(); - break; default: $error = "Action non valide"; require($rep . $vues['erreur']); diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index db2e308c..99a3607f 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -61,4 +61,10 @@ class UserModel require($rep . $vues['erreur']); } } + + public function logout() + { + $_SESSION['role'] = 'visitor'; + header('Location: index.php'); + } } \ No newline at end of file diff --git a/WEB/Model/VisitorModel.php b/WEB/Model/VisitorModel.php index 647a7b16..23ffb231 100644 --- a/WEB/Model/VisitorModel.php +++ b/WEB/Model/VisitorModel.php @@ -82,17 +82,6 @@ class VisitorModel } } - public function goToPresentation() - { - global $rep, $vues, $error; - try { - require($rep . $vues['presentation']); - } catch (Exception $e) { - $error = "Erreur Inconnue"; - require($rep . $vues['erreur']); - } - } - public function goToHome() { global $rep, $vues, $error; @@ -125,34 +114,4 @@ class VisitorModel require($rep . $vues['erreur']); } } - - public function goToEnigme() - { - global $rep, $vues, $error; - try { - require($rep . $vues['enigme']); - } catch (Exception $e) { - $error = "404"; - require($rep . $vues['erreur']); - } - } - - public function goToQueue() - { - global $rep, $vues, $error; - try { - require($rep . $vues['Queue']); - } catch (Exception $e) { - $error = "404"; - require($rep . $vues['erreur']); - } - } - - public function logout() - { - session_unset(); - session_destroy(); - $_SESSION = null; - $this->goToHome(); - } } \ No newline at end of file diff --git a/WEB/index.php b/WEB/index.php index 468267f3..1b8647e6 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -6,8 +6,8 @@ Autoload::charger(); $control = new FrontController(); //session_regenerate_id(true); -session_unset(); -session_destroy(); -$_SESSION = null; +// session_unset(); +// session_destroy(); +// $_SESSION = null; //https://a-pellegrini.developpez.com/temp/tutoriels/php/security/session/#III.2 \ No newline at end of file From 96417d5c8b831778f0ea2e8475a6a631281e7e04 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 5 Dec 2022 15:48:34 +0100 Subject: [PATCH 12/13] Ajout de la factory Utilisateur --- WEB/Controller/EnigmeGateway.php | 10 +++++++--- WEB/Factory/UtilisateurFactory.php | 14 ++++++++++++++ WEB/Model/scripted.db | Bin 53248 -> 53248 bytes 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 WEB/Factory/UtilisateurFactory.php diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 8379835d..9ecba86b 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -56,12 +56,16 @@ class EnigmeGateway $query = "SELECT * FROM Enigme WHERE points IS NOT NULL OR points != 0"; $this->con->executeQuery($query); - $results = $this->con->getResults(); - return $results; + $tabEnigme=EnigmeFactory::create($this->con->getResults()); + return $tabEnigme } public function findSoloEnigma(){ - + $query = "SELECT * FROM Enigme + WHERE points IS NULL OR points = 0"; + $this->con->executeQuery($query); + $tabEnigme=EnigmeFactory::create($this->con->getResults()); + return $tabEnigme } public function findById(string $idEnigme) : array diff --git a/WEB/Factory/UtilisateurFactory.php b/WEB/Factory/UtilisateurFactory.php new file mode 100644 index 00000000..03c8b27f --- /dev/null +++ b/WEB/Factory/UtilisateurFactory.php @@ -0,0 +1,14 @@ +f*hCp;MzM_vOZfR%`NA0Zm+=SlGx4qC3)?Ix;KCOX#>%EC*~rR~ zm7kqhllKxK4wE_GvJE@pCWZ)ah0ZfRw5F(fj1Brz}~M_OxPHnXlCRsjqI f54ivj><`)x$`84-5ip|<1`p!^8%}Stxi3ec4ap|g From a6bb4346b5b983a7347d6ad4794f0a3936891200 Mon Sep 17 00:00:00 2001 From: johan Date: Mon, 5 Dec 2022 15:58:13 +0100 Subject: [PATCH 13/13] Ajout de la utilisateur factory --- WEB/Controller/EnigmeGateway.php | 4 ++-- WEB/Controller/UtilisateurGateway.php | 12 +----------- WEB/Factory/UtilisateurFactory.php | 16 ++++++++++++++-- WEB/index.php | 6 +++--- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/WEB/Controller/EnigmeGateway.php b/WEB/Controller/EnigmeGateway.php index 9ecba86b..796e5c66 100644 --- a/WEB/Controller/EnigmeGateway.php +++ b/WEB/Controller/EnigmeGateway.php @@ -57,7 +57,7 @@ class EnigmeGateway WHERE points IS NOT NULL OR points != 0"; $this->con->executeQuery($query); $tabEnigme=EnigmeFactory::create($this->con->getResults()); - return $tabEnigme + return $tabEnigme; } public function findSoloEnigma(){ @@ -65,7 +65,7 @@ class EnigmeGateway WHERE points IS NULL OR points = 0"; $this->con->executeQuery($query); $tabEnigme=EnigmeFactory::create($this->con->getResults()); - return $tabEnigme + return $tabEnigme; } public function findById(string $idEnigme) : array diff --git a/WEB/Controller/UtilisateurGateway.php b/WEB/Controller/UtilisateurGateway.php index 136ebc06..91b86efd 100644 --- a/WEB/Controller/UtilisateurGateway.php +++ b/WEB/Controller/UtilisateurGateway.php @@ -48,17 +48,7 @@ class UtilisateurGateway ':email' => array($email,SQLITE3_TEXT) )); $results=$this->con->getResults(); - if ($results == null){ - return new Utilisateur("null", "null", "null", false); - } - foreach($results as $row) - { - $email = $row['email']; - $pseudo=$row['pseudo']; - $mdp = $row['mdp']; - $estAdmin = $row['estAdmin']; - } - return new Utilisateur($email, $pseudo, $mdp, $estAdmin); + return UtilisateurFactory::createUtilisateur($results); } public function getMdpByEmail(string $email) : string{ diff --git a/WEB/Factory/UtilisateurFactory.php b/WEB/Factory/UtilisateurFactory.php index 03c8b27f..860f6d63 100644 --- a/WEB/Factory/UtilisateurFactory.php +++ b/WEB/Factory/UtilisateurFactory.php @@ -2,7 +2,20 @@ class UtilisateurFactory { - public static function create(array $results){ + public static function createUtilisateur(array $results){ + if ($results == null){ + return new Utilisateur("null", "null", "null", false); + } + foreach($results as $row) + { + $email = $row['email']; + $pseudo=$row['pseudo']; + $mdp = $row['mdp']; + $estAdmin = $row['estAdmin']; + } + return new Utilisateur($email, $pseudo, $mdp, $estAdmin); + } + public static function createTabUtilisateur(array $results){ $tabUtilisateur=array(); foreach($results as $row) { @@ -10,5 +23,4 @@ class UtilisateurFactory } return $tabUtilisateur; } - } \ No newline at end of file diff --git a/WEB/index.php b/WEB/index.php index 468267f3..1b8647e6 100644 --- a/WEB/index.php +++ b/WEB/index.php @@ -6,8 +6,8 @@ Autoload::charger(); $control = new FrontController(); //session_regenerate_id(true); -session_unset(); -session_destroy(); -$_SESSION = null; +// session_unset(); +// session_destroy(); +// $_SESSION = null; //https://a-pellegrini.developpez.com/temp/tutoriels/php/security/session/#III.2 \ No newline at end of file