From ee688b536656be2d72780c43f2c0706892306a7f Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Mon, 14 Nov 2022 16:31:53 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20et=20v=C3=A9rification=20de?= =?UTF-8?q?=20la=20connection=20et=20de=20l'inscription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WEB/Config/Config.php | 15 ++++++ WEB/Controller/Controller.php | 55 +++++++++++++++++----- WEB/Controller/InvalidMdpException.php | 10 ++++ WEB/Controller/JoueurGateway.php | 40 ++++++++++++++-- WEB/Controller/JoueurNotFoundException.php | 10 ++++ WEB/Controller/Traitement.php | 18 +++---- WEB/View/Error/Erreur.php | 11 +++++ WEB/View/Error/ErreurBd.php | 9 ++++ WEB/View/Error/ErreurLoginEmail.php | 10 ++++ WEB/View/Error/ErreurLoginMdp.php | 10 ++++ WEB/View/Error/ErreurSignUp.php | 10 ++++ WEB/View/src/pages/LogSign/Login.php | 6 +-- WEB/View/src/pages/LogSign/SignUp.php | 11 +---- 13 files changed, 174 insertions(+), 41 deletions(-) create mode 100644 WEB/Config/Config.php create mode 100644 WEB/Controller/InvalidMdpException.php create mode 100644 WEB/Controller/JoueurNotFoundException.php create mode 100644 WEB/View/Error/Erreur.php create mode 100644 WEB/View/Error/ErreurBd.php create mode 100644 WEB/View/Error/ErreurLoginEmail.php create mode 100644 WEB/View/Error/ErreurLoginMdp.php create mode 100644 WEB/View/Error/ErreurSignUp.php diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php new file mode 100644 index 00000000..9ffee740 --- /dev/null +++ b/WEB/Config/Config.php @@ -0,0 +1,15 @@ +con=$con; session_start(); try{ + global $rep, $vues; $action=$_REQUEST['action']; switch($action) { case NULL: //require ('../View/src/pages/Main.html'); header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html'); break; + case "signUp": + $this->signUp(); + break; case "login": $this->login(); break; } } catch (PDOException $e) { - //si erreur BD, pas le cas ici - $dataVueEreur[] = "Erreur inattendue!!! "; - //require(__DIR__.'/../vues/erreur.php'); // ajout du code de la vue ici - } - catch (Exception $e2) - { - $dataVueEreur[] = "Erreur inattendue!!! "; - //require ($rep.$vues['erreur']); + require ($rep.$vues['erreurBd']); } } - private function login() { - $gateway=new JoueurGateway($this->con); - $joueur=new Joueur($_REQUEST['email'], $_REQUEST['username'], $_REQUEST['password']); - $gateway->insert($joueur); - $gateway->showAll(); + private function signUp() { + global $rep, $vues; + try { + $gateway = new JoueurGateway($this->con); + $validation = new Validation(); + if (! $validation->ValidateEmail($_REQUEST['email'])) { + throw (new Exception("Email non valide")); + } + $joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $_REQUEST['password']); + $gateway->insert($joueur); + //$gateway->showAll(); + header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html'); + }catch (Exception $e){ + require($rep.$vues['erreurSignUp']); + } + } + private function login(){ + global $rep, $vues; + try { + $gateway = new JoueurGateway($this->con); + $joueur = $gateway->getJoueurByEmail($_REQUEST['email']); + if ($joueur->getEmail() == null){ + throw new JoueurNotFoundException("Joueur introuvable"); + } + $mdp = $gateway->getMdpByEmail($_REQUEST['email']); + if ($mdp != $_REQUEST['password']){ + throw new InvalidMdpException("Mot de passe invalide"); + } + header('Location: http://londres.uca.local/~nogarnier1/Scripted/WEB/View/src/pages/Main.html'); + }catch (JoueurNotFoundException $e){ + require($rep.$vues['erreurLoginEmail']); + }catch (InvalidMdpException $m) { + require($rep . $vues['erreurLoginMdp']); + } } } \ No newline at end of file diff --git a/WEB/Controller/InvalidMdpException.php b/WEB/Controller/InvalidMdpException.php new file mode 100644 index 00000000..6b8c9097 --- /dev/null +++ b/WEB/Controller/InvalidMdpException.php @@ -0,0 +1,10 @@ +getLine().' in '.$this->getFile() + .': '.$this->getMessage().' Mdp invalide'; + return $errorMsg; + } +} \ No newline at end of file diff --git a/WEB/Controller/JoueurGateway.php b/WEB/Controller/JoueurGateway.php index 0d6b1156..24d72583 100644 --- a/WEB/Controller/JoueurGateway.php +++ b/WEB/Controller/JoueurGateway.php @@ -22,12 +22,12 @@ class JoueurGateway $this->con = $con; } - public function insert(string $email,string $pseudo,string $mdp) : void{ + public function insert(Joueur $joueur) : void{ $query = "INSERT INTO Joueur VALUE (:email,:pseudo,:mdp)"; $this->con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR), - ':pseudo' => array($pseudo,PDO::PARAM_STR), - ':mdp' => array($mdp,PDO::PARAM_STR))); + ':email' => array($joueur->getEmail(),PDO::PARAM_STR), + ':pseudo' => array($joueur->getPseudo(),PDO::PARAM_STR), + ':mdp' => array($joueur->getMdp(),PDO::PARAM_STR))); } public function delete(string $email) : void{ @@ -37,6 +37,38 @@ class JoueurGateway )); } + public function getJoueurByEmail(string $email) : Joueur{ + $query = "SELECT * FROM Joueur 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']; + } + if ($results == null){ + throw new JoueurNotFoundException("Joueur Introuvable"); + } + return new Joueur($email, $pseudo, $mdp); + } + + public function getMdpByEmail(string $email) : string{ + $query = "SELECT mdp FROM Joueur 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){ + throw new InvalidMdpException("Mots de passe Incorrect"); + } + return $mdp; + } + public function showAll() : void{ $query = "SELECT * FROM Joueur"; $this->con->executeQuery($query); diff --git a/WEB/Controller/JoueurNotFoundException.php b/WEB/Controller/JoueurNotFoundException.php new file mode 100644 index 00000000..0b604c42 --- /dev/null +++ b/WEB/Controller/JoueurNotFoundException.php @@ -0,0 +1,10 @@ +getLine().' in '.$this->getFile() + .': '.$this->getMessage().' Joueur not found'; + return $errorMsg; + } +} \ No newline at end of file diff --git a/WEB/Controller/Traitement.php b/WEB/Controller/Traitement.php index 1e7cf661..f366ddc9 100644 --- a/WEB/Controller/Traitement.php +++ b/WEB/Controller/Traitement.php @@ -1,12 +1,6 @@ - - - - - \ No newline at end of file + + +

ERREUR

+

Erreur inatendu

+ + + + + + +

ERREUR

+

Erreur avec la base de donnée

+ + + diff --git a/WEB/View/Error/ErreurLoginEmail.php b/WEB/View/Error/ErreurLoginEmail.php new file mode 100644 index 00000000..f939830c --- /dev/null +++ b/WEB/View/Error/ErreurLoginEmail.php @@ -0,0 +1,10 @@ + + +

ERREUR

+

Joueur introuvable

+ + + + diff --git a/WEB/View/Error/ErreurLoginMdp.php b/WEB/View/Error/ErreurLoginMdp.php new file mode 100644 index 00000000..4db8f12b --- /dev/null +++ b/WEB/View/Error/ErreurLoginMdp.php @@ -0,0 +1,10 @@ + + +

ERREUR

+

Mot de passe invalide

+ + + + diff --git a/WEB/View/Error/ErreurSignUp.php b/WEB/View/Error/ErreurSignUp.php new file mode 100644 index 00000000..2af01518 --- /dev/null +++ b/WEB/View/Error/ErreurSignUp.php @@ -0,0 +1,10 @@ + + +

ERREUR

+

E-mail invalide

+ + + + diff --git a/WEB/View/src/pages/LogSign/Login.php b/WEB/View/src/pages/LogSign/Login.php index f8c053bd..f99615f6 100644 --- a/WEB/View/src/pages/LogSign/Login.php +++ b/WEB/View/src/pages/LogSign/Login.php @@ -15,10 +15,10 @@

Sign up

-
+
- - + +
diff --git a/WEB/View/src/pages/LogSign/SignUp.php b/WEB/View/src/pages/LogSign/SignUp.php index beb22719..1f8c3592 100644 --- a/WEB/View/src/pages/LogSign/SignUp.php +++ b/WEB/View/src/pages/LogSign/SignUp.php @@ -15,7 +15,7 @@

Sign up

- +
@@ -30,19 +30,12 @@
- Sign up - +