diff --git a/WEB/Config/Config.php b/WEB/Config/Config.php index 5a2ef453..1bd68050 100644 --- a/WEB/Config/Config.php +++ b/WEB/Config/Config.php @@ -23,9 +23,5 @@ $vues['signUp'] = 'View/src/pages/LogSign/SignUp.php'; $vues['enigme'] = 'View/src/pages/Enigme/palindrome.html'; //Error -$vues['erreurSignUp'] = 'View/Error/ErreurSignUp.php'; -$vues['erreur'] = 'View/Error/Erreur.php'; -$vues['erreurBd'] = 'View/Error/ErreurBd.php'; -$vues['erreurLoginEmail'] = 'View/Error/ErreurLoginEmail.php'; -$vues['erreurLoginMdp'] = 'View/Error/ErreurLoginMdp.php'; -$vues['erreur404'] = 'View/Error/Erreur404.php'; +$vues['erreur'] = 'View/src/pages/Erreur.php'; +$error = ""; diff --git a/WEB/Config/Validation.php b/WEB/Config/Validation.php index 16477f87..45cb01cd 100644 --- a/WEB/Config/Validation.php +++ b/WEB/Config/Validation.php @@ -30,10 +30,11 @@ class Validation return true; } public function ValidateUsername(string $username) : bool{ - if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" )))) - { - return false; - } + + // if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" )))) + // { + // return false; + // } return true; } public function ValidatePassword(string $password) : bool{ diff --git a/WEB/Controller/Controller.php b/WEB/Controller/Controller.php index 4c58ff95..39139345 100644 --- a/WEB/Controller/Controller.php +++ b/WEB/Controller/Controller.php @@ -1,4 +1,5 @@ con=$con; session_start(); try{ - global $rep, $vues; + global $rep, $vues, $error; $action=$_REQUEST['action']; switch($action) { case NULL: @@ -41,96 +42,111 @@ class Controller } } catch (PDOException $e) { - require ($rep.$vues['erreurBd']); + $error = $e->getMessage(); + require ($rep.$vues['erreur']); } } private function signUp() { - global $rep, $vues, $sel; + global $rep, $vues, $sel, $error; try { $gateway = new JoueurGateway($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'])){ - throw(new InvalidMdpException("Mot de passe non valide")); + $error = "Mots de passe invalides. Il ne doit pas dépasser 100 caractères."; + throw(new Exception("Mot de passe non valide")); } - $password = password_hash($_REQUEST['password']+$selNoHash, PASSWORD_DEFAULT); + $j = $gateway->getJoueurByEmail($_REQUEST['email']); + if ($j != null) { + $error = "Email déjà utilisé."; + throw (new Exception("Email déjà utilisé")); + } + $password = password_hash($_REQUEST['password'], PASSWORD_DEFAULT); $joueur = new Joueur($_REQUEST['email'], $_REQUEST['username'], $password); $gateway->insert($joueur); $_SESSION['connected'] = 'true'; require ($rep.$vues['main']); }catch (Exception $e){ - require($rep.$vues['erreurSignUp']); + require($rep.$vues['erreur']); } } private function login(){ - global $rep, $vues, $sel; + global $rep, $vues, $sel, $error; try { $gateway = new JoueurGateway($this->con); $joueur = $gateway->getJoueurByEmail($_REQUEST['email']); if ($joueur->getEmail() == null){ - throw new JoueurNotFoundException("Joueur introuvable"); + $error = "Joueur non trouvé."; + throw new Exception("Joueur introuvable"); } $mdp = $gateway->getMdpByEmail($_REQUEST['email']); - if (password_verify($mdp, $_REQUEST['password']+$sel)){ - throw new InvalidMdpException("Mot de passe invalide"); + if (password_verify($mdp, $_REQUEST['password'])){ + $error = "Mot de passe incorrect."; + throw new Exception("Mot de passe invalide"); } $_SESSION['connected'] = 'true'; require ($rep.$vues['main']); - }catch (JoueurNotFoundException $e){ - require($rep.$vues['erreurLoginEmail']); - }catch (InvalidMdpException $m) { - require($rep . $vues['erreurLoginMdp']); + }catch (Exception $e){ + require($rep.$vues['erreur']); } } + // require error page with given message private function goToPresentation() { - global $rep, $vues; + global $rep, $vues, $error; try { require ($rep.$vues['presenation']); }catch (Exception $e){ - require($rep.$vues['erreur404']); + $error = "Erreur Inconnue"; + require($rep.$vues['erreur']); } } private function goToHome() { - global $rep, $vues; + global $rep, $vues, $error; try { require ($rep.$vues['main']); }catch (Exception $e){ - require($rep.$vues['erreur404']); + $error = "404"; + require($rep.$vues['erreur']); } } private function goToLogin() { - global $rep, $vues; + global $rep, $vues, $error; try { require ($rep.$vues['login']); }catch (Exception $e){ - require($rep.$vues['erreur404']); + $error = "404"; + require($rep.$vues['erreur']); } } private function goToSignUp() { - global $rep, $vues; + global $rep, $vues, $error; try { require ($rep.$vues['signUp']); }catch (Exception $e){ - require($rep.$vues['erreur404']); + $error = "404"; + require($rep.$vues['erreur']); } } private function goToEnigme() { - global $rep, $vues; + global $rep, $vues, $error; try { require ($rep.$vues['enigme']); }catch (Exception $e){ - require($rep.$vues['erreur404']); + $error = "404"; + require($rep.$vues['erreur']); } } } \ No newline at end of file diff --git a/WEB/Controller/InvalidMdpException.php b/WEB/Controller/InvalidMdpException.php deleted file mode 100644 index 6b8c9097..00000000 --- a/WEB/Controller/InvalidMdpException.php +++ /dev/null @@ -1,10 +0,0 @@ -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 f6737e72..0f867088 100644 --- a/WEB/Controller/JoueurGateway.php +++ b/WEB/Controller/JoueurGateway.php @@ -35,6 +35,7 @@ class JoueurGateway } public function getJoueurByEmail(string $email) : Joueur{ + global $error; $query = "SELECT * FROM Joueur WHERE email=:email"; $this->con->executeQuery($query, array( ':email' => array($email,PDO::PARAM_STR) @@ -46,12 +47,14 @@ class JoueurGateway $mdp=$row['mdp']; } if ($results == null){ - throw new JoueurNotFoundException("Joueur Introuvable"); + $error = "Joueur non trouvé."; + throw new Exception("Joueur Introuvable"); } return new Joueur($email, $pseudo, $mdp); } public function getMdpByEmail(string $email) : string{ + global $error; $query = "SELECT mdp FROM Joueur WHERE email=:email"; $this->con->executeQuery($query, array( ':email' => array($email,PDO::PARAM_STR) @@ -61,7 +64,8 @@ class JoueurGateway $mdp=$row['mdp']; } if ($results == null){ - throw new InvalidMdpException("Mots de passe Incorrect"); + $error = "Mot de passe non trouvé."; + throw new Exception("Mots de passe Incorrect"); } return $mdp; } diff --git a/WEB/Controller/JoueurNotFoundException.php b/WEB/Controller/JoueurNotFoundException.php deleted file mode 100644 index 0b604c42..00000000 --- a/WEB/Controller/JoueurNotFoundException.php +++ /dev/null @@ -1,10 +0,0 @@ -getLine().' in '.$this->getFile() - .': '.$this->getMessage().' Joueur not found'; - return $errorMsg; - } -} \ No newline at end of file diff --git a/WEB/View/Error/Erreur.php b/WEB/View/Error/Erreur.php deleted file mode 100644 index e11be05c..00000000 --- a/WEB/View/Error/Erreur.php +++ /dev/null @@ -1,9 +0,0 @@ - -
-Erreur inatendu
- - - \ No newline at end of file diff --git a/WEB/View/Error/Erreur404.php b/WEB/View/Error/Erreur404.php deleted file mode 100644 index 84b9c616..00000000 --- a/WEB/View/Error/Erreur404.php +++ /dev/null @@ -1,9 +0,0 @@ - - -Page introuvable
- - - diff --git a/WEB/View/Error/ErreurBd.php b/WEB/View/Error/ErreurBd.php deleted file mode 100644 index 8c80510e..00000000 --- a/WEB/View/Error/ErreurBd.php +++ /dev/null @@ -1,9 +0,0 @@ - - -Erreur avec la base de donnée
- - - diff --git a/WEB/View/Error/ErreurLoginEmail.php b/WEB/View/Error/ErreurLoginEmail.php deleted file mode 100644 index f939830c..00000000 --- a/WEB/View/Error/ErreurLoginEmail.php +++ /dev/null @@ -1,10 +0,0 @@ - - -Joueur introuvable
- - - - diff --git a/WEB/View/Error/ErreurLoginMdp.php b/WEB/View/Error/ErreurLoginMdp.php deleted file mode 100644 index 4db8f12b..00000000 --- a/WEB/View/Error/ErreurLoginMdp.php +++ /dev/null @@ -1,10 +0,0 @@ - - -Mot de passe invalide
- - - - diff --git a/WEB/View/Error/ErreurSignUp.php b/WEB/View/Error/ErreurSignUp.php deleted file mode 100644 index e27b2689..00000000 --- a/WEB/View/Error/ErreurSignUp.php +++ /dev/null @@ -1,10 +0,0 @@ - - -La page que vous recherchez a peut-être été supprimée, a changé de nom ou est temporairement indisponible.
'; + echo 'Veuillez essayer de retourner en arrière ou de retourné à la page d\'accueil.
'; + echo 'Bonne Chance Utilisateur.
'; +} +elseif ($error == ""){ + echo 'Erreur inconnue
'; + echo 'Veuillez essayer de retourner en arrière ou de retourné à la page d\'accueil.
'; + echo 'Bonne Chance Utilisateur.
'; +} + +else{ + echo ''.$error.'
'; + echo 'Veuillez essayer de retourner en arrière ou de retourné à la page d\'accueil.
'; + echo 'Bonne Chance Utilisateur.
'; +} +?> +