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 @@