From 5aaf71c7665021703b9b50582144e5c98dfc5486 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Thu, 10 Nov 2022 09:58:42 +0100 Subject: [PATCH 1/2] Class Controller.php + JoueurGateway.php + Traitement.php + ajout de l'inscription --- WEB/Controller/Controller.php | 45 ++++++++++++++++++ WEB/Controller/JoueurGateway.php | 44 ++++++++++++++++++ WEB/Controller/Traitement.php | 12 +++++ WEB/Controller/Validation.php | 28 +++++++++++- WEB/Controller/get.php | 43 ------------------ WEB/Model/Joueur.php | 63 ++++++++++++++++++++++++++ WEB/View/src/pages/LogSign/Login.php | 15 +++--- WEB/View/src/pages/LogSign/SignUp.html | 45 ------------------ WEB/View/src/pages/LogSign/SignUp.php | 51 +++++++++++++++++++++ 9 files changed, 251 insertions(+), 95 deletions(-) create mode 100644 WEB/Controller/Controller.php create mode 100644 WEB/Controller/JoueurGateway.php create mode 100644 WEB/Controller/Traitement.php delete mode 100644 WEB/Controller/get.php delete mode 100644 WEB/View/src/pages/LogSign/SignUp.html create mode 100644 WEB/View/src/pages/LogSign/SignUp.php diff --git a/WEB/Controller/Controller.php b/WEB/Controller/Controller.php new file mode 100644 index 00000000..8f2e60b2 --- /dev/null +++ b/WEB/Controller/Controller.php @@ -0,0 +1,45 @@ +con=$con; + session_start(); + try{ + $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 "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']); + } + } + + private function login() { + $gateway=new JoueurGateway($this->con); + $joueur=new Joueur($_REQUEST['email'], $_REQUEST['username'], $_REQUEST['password']); + $gateway->insert($joueur); + $gateway->showAll(); + } +} \ No newline at end of file diff --git a/WEB/Controller/JoueurGateway.php b/WEB/Controller/JoueurGateway.php new file mode 100644 index 00000000..f8e8be97 --- /dev/null +++ b/WEB/Controller/JoueurGateway.php @@ -0,0 +1,44 @@ +con = $con; + } + + /** + * @param Connection $con + */ + public function setCon(Connection $con): void + { + $this->con = $con; + } + + public function insert(Joueur $joueur) : void{ + $query = "INSERT INTO Joueur VALUE (:email,:pseudo,:mdp)"; + $this->con->executeQuery($query, array( + ':email' => array($joueur->getEmail(),PDO::PARAM_STR), + ':pseudo' => array($joueur->getPseudo(),PDO::PARAM_STR), + ':mdp' => array($joueur->getMdp(),PDO::PARAM_STR))); + } + + public function showAll() : void{ + $query = "SELECT * FROM Joueur"; + $this->con->executeQuery($query, array()); + $results=$this->con->getResults(); + foreach ($results as $row) + echo $row['email'] . '
'; + echo $row['pseudo'] . '
'; + echo $row['mdp'] . '
'; + echo '
'; + + } +} \ No newline at end of file diff --git a/WEB/Controller/Traitement.php b/WEB/Controller/Traitement.php new file mode 100644 index 00000000..1e7cf661 --- /dev/null +++ b/WEB/Controller/Traitement.php @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/WEB/Controller/Validation.php b/WEB/Controller/Validation.php index fb682eab..2fe55341 100644 --- a/WEB/Controller/Validation.php +++ b/WEB/Controller/Validation.php @@ -2,5 +2,31 @@ class Validation { + public function ValidateSet($var) :bool{ + if (isset($var)) { + return true; + } + return false; + } -} \ No newline at end of file + public function ValidateNotEmpty($var) :bool{ + if (empty($var)) { + return false; + } + return true; + } + + public function ValidateURL(string $url) :bool{ + if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) { + return false; + } + return true; + } + + public function ValidateEmail(string $email) :bool{ + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + return false; + } + return true; + } +} diff --git a/WEB/Controller/get.php b/WEB/Controller/get.php deleted file mode 100644 index 923b93ef..00000000 --- a/WEB/Controller/get.php +++ /dev/null @@ -1,43 +0,0 @@ - - - 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(); - } - } - $email = $_POST['email']; - $nom = $_POST['username']; - $mdp = $_POST['password']; - - $dsn = 'mysql:host=localhost;dbname=dbnogarnier1'; - $user = 'nogarnier1'; - $password = 'achanger'; - - $con=new Connection($dsn, $user, $password); - $query = "INSERT INTO Joueur VALUE (:email,:nom,:mdp)"; - $con->executeQuery($query, array( - ':email' => array($email,PDO::PARAM_STR), - ':nom' => array($nom,PDO::PARAM_STR), - ':mdp' => array($mdp,PDO::PARAM_STR))); - - $db = new PDO($dsn, $user, $password); - $query= 'SELECT * FROM Joueur'; - $stmt=$db->prepare($query); - $stmt->execute(); - $results=$stmt->fetchall(); - Foreach ($results as $row) - echo $row['email'].'
'; - ?> - - \ No newline at end of file diff --git a/WEB/Model/Joueur.php b/WEB/Model/Joueur.php index 44c2ad8c..16635cb1 100644 --- a/WEB/Model/Joueur.php +++ b/WEB/Model/Joueur.php @@ -2,5 +2,68 @@ class Joueur { + private string $email; + private string $pseudo; + private string $mdp; + + /** + * @param string $email + * @param string $pseudo + * @param string $mdp + */ + public function __construct(string $email, string $pseudo, string $mdp) + { + $this->email = $email; + $this->pseudo = $pseudo; + $this->mdp = $mdp; + } + + /** + * @return string + */ + public function getEmail(): string + { + return $this->email; + } + + /** + * @param string $email + */ + public function setEmail(string $email): void + { + $this->email = $email; + } + + /** + * @return string + */ + public function getPseudo(): string + { + return $this->pseudo; + } + + /** + * @param string $pseudo + */ + public function setPseudo(string $pseudo): void + { + $this->pseudo = $pseudo; + } + + /** + * @return string + */ + public function getMdp(): string + { + return $this->mdp; + } + + /** + * @param string $mdp + */ + public function setMdp(string $mdp): void + { + $this->mdp = $mdp; + } } \ No newline at end of file diff --git a/WEB/View/src/pages/LogSign/Login.php b/WEB/View/src/pages/LogSign/Login.php index 0f53216c..f8c053bd 100644 --- a/WEB/View/src/pages/LogSign/Login.php +++ b/WEB/View/src/pages/LogSign/Login.php @@ -9,17 +9,13 @@ Login -< +
diff --git a/WEB/View/src/pages/LogSign/SignUp.html b/WEB/View/src/pages/LogSign/SignUp.html deleted file mode 100644 index 93d1cadb..00000000 --- a/WEB/View/src/pages/LogSign/SignUp.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - - - - - Login - - -
- -
- - \ No newline at end of file diff --git a/WEB/View/src/pages/LogSign/SignUp.php b/WEB/View/src/pages/LogSign/SignUp.php new file mode 100644 index 00000000..beb22719 --- /dev/null +++ b/WEB/View/src/pages/LogSign/SignUp.php @@ -0,0 +1,51 @@ + + + + + + + + + + Login + + +
+ +
+ + \ No newline at end of file From 4d7c70e16c295916312656c5a0ddfe5d3e151009 Mon Sep 17 00:00:00 2001 From: Noe GARNIER Date: Thu, 10 Nov 2022 10:01:50 +0100 Subject: [PATCH 2/2] Class Controller.php + JoueurGateway.php + Traitement.php + ajout de l'inscription --- .idea/.gitignore | 8 ++++++++ .idea/Scripted.iml | 8 ++++++++ .idea/deployment.xml | 14 ++++++++++++++ .idea/inspectionProfiles/Project_Default.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/php.xml | 6 ++++++ .idea/vcs.xml | 6 ++++++ 7 files changed, 57 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/Scripted.iml create mode 100644 .idea/deployment.xml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..73f69e09 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Scripted.iml b/.idea/Scripted.iml new file mode 100644 index 00000000..c956989b --- /dev/null +++ b/.idea/Scripted.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/deployment.xml b/.idea/deployment.xml new file mode 100644 index 00000000..5cb703ee --- /dev/null +++ b/.idea/deployment.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..be4b2867 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..6200ce1b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 00000000..97a38d70 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file