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