diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100755 index 0000000..73f69e0 --- /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/ScienceQuest.iml b/.idea/ScienceQuest.iml new file mode 100755 index 0000000..c956989 --- /dev/null +++ b/.idea/ScienceQuest.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100755 index 0000000..c5871cc --- /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 100755 index 0000000..0e09af4 --- /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 100755 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/project/src/.gitignore b/project/src/.gitignore new file mode 100755 index 0000000..da055ac --- /dev/null +++ b/project/src/.gitignore @@ -0,0 +1,4 @@ +vendor/ +composer.lock +js/bootstrap*.js* +css/bootstrap*.css* \ No newline at end of file diff --git a/project/src/composer.json b/project/src/composer.json index c506a42..7839d36 100755 --- a/project/src/composer.json +++ b/project/src/composer.json @@ -3,12 +3,20 @@ "psr-4": { "controller\\": "controller/", "config\\": "config/", - "model\\": ["model/", "model/gateways/", "model/metier/"] + "model\\": ["model/", "model/mdl/", "model/gateways/", "model/metier/", "model/exception/"] } }, "require": { "altorouter/altorouter": "^2.0", "twig/twig": "^3.7", - "ext-pdo": "*" + "twbs/bootstrap": "^5.3" + }, + "scripts": { + "post-update-cmd": [ + "rm -f ./js/bootstrap*.js*", + "rm -f ./css/bootstrap*.css*", + "cp ./vendor/twbs/bootstrap/dist/js/* ./js/", + "cp ./vendor/twbs/bootstrap/dist/css/* ./css/" + ] } } diff --git a/project/src/composer.lock b/project/src/composer.lock index 510df4e..7dfd67d 100755 --- a/project/src/composer.lock +++ b/project/src/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1dace5e05aa6a83586228ea227d11d71", + "content-hash": "8ac61264e1d011c0b663d8c3dbdfc99f", "packages": [ { "name": "altorouter/altorouter", @@ -231,6 +231,56 @@ ], "time": "2023-07-28T09:04:16+00:00" }, + { + "name": "twbs/bootstrap", + "version": "v5.3.2", + "source": { + "type": "git", + "url": "https://github.com/twbs/bootstrap.git", + "reference": "344e912d04b5b6a04482113eff20ab416ff01048" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/344e912d04b5b6a04482113eff20ab416ff01048", + "reference": "344e912d04b5b6a04482113eff20ab416ff01048", + "shasum": "" + }, + "replace": { + "twitter/bootstrap": "self.version" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Otto", + "email": "markdotto@gmail.com" + }, + { + "name": "Jacob Thornton", + "email": "jacobthornton@gmail.com" + } + ], + "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", + "homepage": "https://getbootstrap.com/", + "keywords": [ + "JS", + "css", + "framework", + "front-end", + "mobile-first", + "responsive", + "sass", + "web" + ], + "support": { + "issues": "https://github.com/twbs/bootstrap/issues", + "source": "https://github.com/twbs/bootstrap/tree/v5.3.2" + }, + "time": "2023-09-14T14:19:27+00:00" + }, { "name": "twig/twig", "version": "v3.7.1", @@ -309,9 +359,7 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": { - "ext-pdo": "*" - }, + "platform": [], "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/project/src/config/Validation.php b/project/src/config/Validation.php index 3140c64..c9f2d58 100755 --- a/project/src/config/Validation.php +++ b/project/src/config/Validation.php @@ -1,12 +1,15 @@ __DIR__.'/../', + "db" => ["dsn" => 'pgsql:host=localhost;dbname=dbrebeuret', + "login" => 'rebeuret', + "mdp" => 'achanger'], + "templates" => ["index" => 'vues/index.php', + "pseudo" => 'pseudo.html', + "pendu" => "pendu.html", + "penduScore" => 'penduScore.html'] +]; ?> \ No newline at end of file diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index f6eb100..012275a 100755 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -4,24 +4,21 @@ namespace controller; use config\Validation; use http\Params; use model\Connection; -use model\ModelAdmin; -use model\UserGateway; +use model\LoginException; +use model\MdlAdmin; +use model\MdlUser; class FrontController { + private Connection $con; public function __construct() { global $twig, $router; - global $login; - global $mdp; - global $base; global $basePath; - $con = new Connection($base, $login, $mdp); - //altorouter $router = new \AltoRouter(); - $router->setBasePath('ScienceQuest/Project/src/'); + $router->setBasePath($basePath); $router->map('GET|POST','/[a:action]?','UserController'); $router->map('GET|POST','/admin/[a:action]','AdminController'); @@ -47,22 +44,27 @@ class FrontController } switch($match['target']) { + case 'UserController': $this->callController('UserController',$match); break; case 'AdminController': $action = $match['params']['action']; - if (!ModelAdmin::isAdmin()) { + if (!MdlAdmin::isAdmin()) { $action = 'login'; } $this->callController('AdminController',$action); + + case 'PseudoController': + $this->callController('PseudoController',$match); break; case 'validationFormulaire': $this->ValidationFormulaire($dVueErreur, $dVue); break; + //mauvaise action default: $dVueErreur[] = "Erreur d'appel php"; echo $twig->render('accueil.html', ['dVueErreur' => $dVueErreur]); @@ -83,6 +85,7 @@ class FrontController exit(0); } + private function callController(string $cont, array $match) { global $twig; @@ -101,12 +104,25 @@ class FrontController { global $twig; - $game = $_POST['game'] ?? ''; - $difficulty = $_POST['difficulty'] ?? ''; - \config\Validation::val_form($game, $difficulty, $dVueErreur); + $id_jeu = $_POST['jeu'] ?? ''; + $id_difficulte = $_POST['difficulte'] ?? ''; + try{ + \config\Validation::val_form($id_jeu, $id_difficulte, $dVueErreur); + }catch (\model\ValidationException $ex){ + $this->CreateParty($dVueErreur); + }catch (\Exception $ex){ + $this->CreateParty($dVueErreur); + } - $dVue['info'] = "Jeu '$game' créé avec la difficulté $difficulty"; + if(count($dVueErreur) == 0){ + $jeu = (new \model\MdlJeu())->getFromId($id_jeu); + $difficulte = (new \model\MdlDifficulte())->getFromId($id_difficulte); + $_SESSION['configuration'] = new \model\ConfigurationJeu($jeu, $difficulte); - echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); - } + header("Location: /pseudo"); + #echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); + }else{ + $this->CreateParty($dVueErreur); + } + } } diff --git a/project/src/controller/PenduController.php b/project/src/controller/PenduController.php new file mode 100755 index 0000000..f881d34 --- /dev/null +++ b/project/src/controller/PenduController.php @@ -0,0 +1,86 @@ +dVue = []; + $this->dVueErreur = []; + if(isset($_SESSION['pendu']) && Validation::valMdlPendu($_SESSION['pendu'], $this->dVueErreur)){ + $this->pendu = $_SESSION['pendu']; + }else{ + $this->reinit(); + } + + if(isset($_POST['lettre'])){ + try{ + $this->pendu->jouerLettre($_POST['lettre']); + }catch (ValidationException $e){ + $this->dVueErreur[] = $e->getMessage(); + } + } + + if($this->pendu->aGagne()){ + $this->renderAgagne(); + }elseif($this->pendu->aPerdu()){ + $this->renderAPerdu(); + }else{ + $this->renderJeu(); + } + } + + private function reinit(){ + $mdlScientifique = new MdlScientifique(); + $scientifique = $mdlScientifique->getRandom(); + $this->pendu = new MdlPendu($scientifique); + $_SESSION['pendu'] = $this->pendu; + } + + private function renderJeu(){ + global $twig, $config; + $this->dVue['decouvert'] = $this->pendu->getDecouvert(); + $this->dVue['essaisRestant'] = $this->pendu->getEssaisRestant(); + $lettreUtilisees = $this->pendu->getLettreUtilisees(); + sort($lettreUtilisees); + $this->dVue['lettresUtilisees'] = $lettreUtilisees; + echo $twig->render($config['templates']['pendu'], ['dVue' => $this->dVue, 'dVueErreur'=>$this->dVueErreur]); + } + + private function renderAgagne(){ + $this->dVue['messageScore'] = "Vous avez gagné !"; + $this->renderScore(); + } + + private function renderAPerdu(){ + $this->dVue['messageScore'] = "Vous avez perdu !"; + $this->renderScore(); + } + + private function renderScore(){ + global $twig, $config; + $this->dVue['nbTours'] = $this->pendu->getNbTours(); + $this->dVue['nbFails'] = $this->pendu->getNbFails(); + $scientifique = $this->pendu->getScientifique(); + $dScientifique = []; + $dScientifique['nom'] = $scientifique->getNom(); + $dScientifique['prenom'] = $scientifique->getPrenom(); + $dScientifique['sexe'] = $scientifique->getSexe()->getLibelle(); + $dScientifique['thematique'] = $scientifique->getThematique()->getLibelle(); + $dScientifique['dateNaiss'] = $scientifique->getDateNaiss()->format('d/m/Y'); + $this->dVue['scientifique'] = $dScientifique; + unset($_SESSION['pendu']); + + echo $twig->render($config['templates']['penduScore'], ["dVue" => $this->dVue]); + } +} \ No newline at end of file diff --git a/project/src/controller/PseudoController.php b/project/src/controller/PseudoController.php new file mode 100755 index 0000000..cf4ad97 --- /dev/null +++ b/project/src/controller/PseudoController.php @@ -0,0 +1,42 @@ +insertInvite($pseudo, session_id()); + }catch(ValidationException $e){ + + }catch(PseudoDejaPrisException $e){ + $dVueErreur[] = "Pseudo déjà pris"; + }catch(IdSessionDoubleException $e){ + try{ + $role = $mdlInvite->setPseudo($e->getIdJoueur(), $pseudo); + }catch(PseudoDejaPrisException $e){ + $dVueErreur[] = "Pseudo déjà pris"; + } + } + + if(isset($role)){ + $_SESSION['role'] = $role; + header('Location: jouer'); + } + } + echo $twig->render($config['templates']['pseudo'], ["dVue" => $dVue, "dVueErreur" => $dVueErreur]); + } +} \ No newline at end of file diff --git a/project/src/controller/UserController.php b/project/src/controller/UserController.php index 1784be0..0ea78e9 100755 --- a/project/src/controller/UserController.php +++ b/project/src/controller/UserController.php @@ -2,39 +2,78 @@ namespace controller; +use config\Validation; use model\Connection; use model\GameGateway; +use model\ValidationException; class UserController { - public function CreateParty() { + + public function accueil(array $params) { global $twig; - $dVueCreate = \model\GameGateway::getGames(); - echo $twig->render('create.html', ['dVueCreate' => $dVueCreate]); + echo $twig->render('accueil.html'); } - public function JoinParty() { + public function joinParty(array $params) { global $twig; - global $base; - global $login; - global $mdp; - - $con = new Connection($base, $login, $mdp); - $gg = new GameGateway($con); - if(!isset($_REQUEST['code'])) { + if(isset($_POST['codeInvitation'])){ + $codeInvitation = $_POST['codeInvitation']; + Validation::valCodeInvitation($codeInvitation, $dVueErreur); echo $twig->render('join.html'); - } elseif (empty($_REQUEST['code']) || !sizeof($gg->getGameByCode($_REQUEST['code']))) { - $dErreur[] = 'Code de partie invalide'; - echo $twig->render('join.html',['dErreur' => $dErreur]); - } else { - // rejoindre la partie } } - public function accueil(array $params) { + public function jouer(array $params) { + global $twig, $config; + $dVue = []; + $dVueErreur = []; + + if(isset($_SESSION["configuration"]) && isset($_SESSION['role'])){ + try{ + $role = $_SESSION['role']; + $role = Validation::valRole($role, $dVueErreur); + $configurationJeu = $_SESSION['configuration']; + $configurationJeu = Validation::valConfigurationJeu($configurationJeu, $dVueErreur); + }catch(ValidationException $e){ + header('Location: .'); + } + + if(count($dVueErreur) == 0){ + $idJeu = $configurationJeu->getJeu()->getId(); + switch($idJeu){ + case 3: + new PenduController($role, $configurationJeu); + break; + default: + throw new Exception("Jeu non défini !"); + break; + } + } + }else{ + header("Location: ."); + } + } + + public function createParty(array $params) : void + { global $twig; + global $dVueErreur; - echo $twig->render('accueil.html'); + $listJeu = (new \model\MdlJeu())->getAll(); + $listDifficulte = (new \model\MdlDifficulte())->getAll(); + + $dVueCreateJeu = []; + foreach($listJeu as $jeu){ + $dVueCreateJeu[] = ['id' => $jeu->getId(), 'nom' => $jeu->getNom()]; + } + + $dVueCreateDifficulte = []; + foreach($listDifficulte as $difficulte){ + $dVueCreateDifficulte[] = ['id' => $difficulte->getId(), 'libelle' => $difficulte->getLibelle()]; + } + + echo $twig->render('create.html', ["dVueErreur" => $dVueErreur, 'dVueCreate' => ["jeux" => $dVueCreateJeu, "difficultes" => $dVueCreateDifficulte]]); } } \ No newline at end of file diff --git a/project/src/db.sql b/project/src/db.sql new file mode 100755 index 0000000..9cc2a25 --- /dev/null +++ b/project/src/db.sql @@ -0,0 +1,182 @@ +-- Testé sous pgsql 15 + +DROP TABLE IF EXISTS Reponse; + +DROP TABLE IF EXISTS Question; + +DROP TABLE IF EXISTS Admin; + +DROP TABLE IF EXISTS Partie; + +DROP TABLE IF EXISTS Jeu; + +DROP TABLE IF EXISTS Decouvrir; + +DROP TABLE IF EXISTS Utilisateur; + +DROP TABLE IF EXISTS Invite; + +DROP TABLE IF EXISTS Joueur; + +DROP TABLE IF EXISTS Indice; + +DROP TABLE IF EXISTS Scientifique; + +DROP TABLE IF EXISTS Thematique; + +DROP TABLE IF EXISTS Difficulte; + +DROP TABLE IF EXISTS Sexe; + + +-- THEMATIQUE + +CREATE TABLE Thematique( + id SERIAL PRIMARY KEY, + libelle varchar(128) NOT NULL UNIQUE +); + + +-- DIFFICULTE + +CREATE TABLE Difficulte( + id SERIAL PRIMARY KEY, + libelle varchar(128) NOT NULL UNIQUE +); + + +-- SEXE + +CREATE TABLE Sexe( + id SERIAL PRIMARY KEY, + libelle varchar(128) NOT NULL UNIQUE +); + + +-- SCIENTIFIQUE + +CREATE TABLE Scientifique( + id SERIAL PRIMARY KEY, + nom varchar(128) NOT NULL, + prenom varchar(128) NOT NULL, + photo varchar(512) NOT NULL, + dateNaissance date NOT NULL, + descriptif text NOT NULL, + ratioTrouvee numeric(5,4), + idThematique integer REFERENCES Thematique(id), + idDifficulte integer REFERENCES Difficulte(id), + idSexe integer REFERENCES Sexe(id) +); + + +-- INDICE + +CREATE TABLE Indice( + id SERIAL PRIMARY KEY, + libelle varchar(512) NOT NULL UNIQUE, + idScientifique integer REFERENCES Scientifique(id) +); + + +-- QUESTION + +CREATE TABLE Question( + id SERIAL PRIMARY KEY, + question varchar(256) NOT NULL UNIQUE +); + + +-- REPONSE + +CREATE TABLE Reponse( + id SERIAL PRIMARY KEY, + reponse varchar(255) NOT NULL, + idQuestion integer REFERENCES Question(id), + idScientifique integer REFERENCES Scientifique(id) +); + + +-- ADMIN + +CREATE TABLE Admin( + id SERIAL PRIMARY KEY, + email varchar(255) NOT NULL UNIQUE, + password varchar(255) NOT NULL +); + + +-- JOUEUR + +CREATE TABLE Joueur( + id SERIAL PRIMARY KEY, + pseudo varchar(255) NOT NULL UNIQUE +); + + +-- Invite + +CREATE TABLE Invite( + idJoueur integer PRIMARY KEY REFERENCES Joueur(id), + idSession varchar(255) NOT NULL UNIQUE +); + + +-- Utilisateur + +CREATE TABLE Utilisateur( + idJoueur integer PRIMARY KEY REFERENCES Joueur(id), + email varchar(255) NOT NULL UNIQUE, + password varchar(255) NOT NULL +); + + +-- Decouvrir + +CREATE TABLE Decouvrir( + idUtilisateur integer REFERENCES Utilisateur(idJoueur), + idScientifique integer REFERENCES Scientifique(id), + PRIMARY KEY (idUtilisateur, idScientifique) +); + + +-- Jeu + +CREATE TABLE Jeu( + id SERIAL PRIMARY KEY, + nom varchar(128) NOT NULL UNIQUE, + nbrParties integer NOT NULL DEFAULT 0 +); + + +-- Partie + +CREATE TABLE Partie( + id SERIAL PRIMARY KEY, + codeInvitation varchar(10) NOT NULL UNIQUE, + idJoueur integer REFERENCES Joueur(id), + idJeu integer REFERENCES Jeu(id) +); + + +-- INSERTS + +INSERT INTO Jeu(nom) VALUES ('Qui-est-ce ?'),('Kahoot'), ('Pendu'); + +INSERT INTO Difficulte(libelle) VALUES ('Facile'),('Intermédiaire'),('Difficile'); + +INSERT INTO Sexe(libelle) VALUES ('Homme'),('Femme'); + +INSERT INTO Thematique(libelle) VALUES ('Nucléaire'),('Mathématiques'); + +INSERT INTO Scientifique(nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe) +VALUES + ('nomToto', 'prenomToto', '', CURRENT_DATE, 'desc', 0, 1, 1, 1), + ('nomTiti', 'prenomTiti', '', CURRENT_DATE, 'desc', 0, 2, 2, 2); + + +INSERT INTO Joueur(id,pseudo) VALUES (1337, 'moi, le meilleur joueur du monde'); +INSERT INTO Utilisateur(idJoueur,email,password) VALUES (1337, 'joueur','$2y$10$juGnlWC9cS19popEKLZsYeir0Jl39k6hDl0dpaCix00FDcdiEbtmS'); +-- mdp = test + +INSERT INTO Admin(id,email,password) VALUES (1, 'admin','$2y$10$juGnlWC9cS19popEKLZsYeir0Jl39k6hDl0dpaCix00FDcdiEbtmS'); +-- mdp = test diff --git a/project/src/index.php b/project/src/index.php index 9a7d476..74f761c 100755 --- a/project/src/index.php +++ b/project/src/index.php @@ -11,27 +11,8 @@ 'cache' => false, ]); - $cont = new FrontController(); - - - - -/* -try{ - $con=new model\Connection($dsn,$login,$mdp); - - $query = "SELECT * FROM categorie WHERE id=:id"; - + $dVueErreur = array(); + $basePath = preg_replace('/\/index.php/i', '', $_SERVER['PHP_SELF']); - echo $con->executeQuery($query, array(':id' => array(1, PDO::PARAM_INT) ) ); - - $results=$con->getResults(); - Foreach ($results as $row) - print $row['titre']; - - -} -catch( PDOException $Exception ) { - echo 'erreur'; - echo $Exception->getMessage();} -*/ \ No newline at end of file + $cont = new FrontController(); + \ No newline at end of file diff --git a/project/src/model/ModelAdmin.php b/project/src/model/ModelAdmin.php deleted file mode 100755 index e0775fb..0000000 --- a/project/src/model/ModelAdmin.php +++ /dev/null @@ -1,25 +0,0 @@ -idJoueur=$idJoueur; + $this->idSession=$idSession; + } + + public function getIdJoueur():int{ + return $this->idJoueur; + } + + public function getIdSession(): string{ + return $this->idSession; + } +} \ No newline at end of file diff --git a/project/src/controller/LoginException.php b/project/src/model/exception/LoginException.php similarity index 68% rename from project/src/controller/LoginException.php rename to project/src/model/exception/LoginException.php index 20b834b..816f535 100755 --- a/project/src/controller/LoginException.php +++ b/project/src/model/exception/LoginException.php @@ -1,6 +1,6 @@ con=$con; } - public function login(string $username, string $password): bool + public function login(string $email, string $password): bool + { + $sql = "SELECT * FROM Admin WHERE email=:email"; + $this->con->executeQuery($sql, array( + ':email' => array($email, \PDO::PARAM_STR) + )); + + $result = $this->con->getOneResult(); + + if (!empty($result)) { + return password_verify($password,$result['password']); + } + return false; + } + public function addUser(string $email, string $password): void + { + $sql = "INSERT INTO Admin (email, password) VALUES (:email, :password)"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); + $stmt->execute(); + } + public function deleteUser(int $id): void { - $sql = "SELECT * FROM admin WHERE username=:username"; + $sql = "DELETE FROM Admin WHERE id=:id"; $stmt = $this->con->prepare($sql); - $stmt->bindValue(':username', $username); + $stmt->bindValue(':id', $id); + $stmt->execute(); + } + public function updateUser(int $id, string $email, string $password): void + { + $sql = "UPDATE Admin SET email=:email, password=:password WHERE id=:id"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':id', $id); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); + $stmt->execute(); + } + public function getUser(int $id): User + { + $sql = "SELECT * FROM Admin WHERE id=:id"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':id', $id); $stmt->execute(); $result = $stmt->fetch(); - if ($result && password_verify($password, $result['password'])) { - return true; + return new User($result['id'], $result['email'], $result['password']); + } + public function getUsers(): array + { + $sql = "SELECT * FROM Admin"; + $stmt = $this->con->prepare($sql); + $stmt->execute(); + $result = $stmt->fetchAll(); + $users = []; + foreach ($result as $user) { + $users[] = new User($user['id'], $user['email'], $user['password']); } - return false; + return $users; + } + public function getHashedPasswordById(int $id): string + { + $sql = "SELECT password FROM Admin WHERE id=:id"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':id', $id); + $stmt->execute(); + $result = $stmt->fetch(); + return $result['password']; } - public function getHashedPassword(string $username): string + public function getHashedPassword(int $email): string { - $sql = "SELECT password FROM user WHERE username=:username"; + $sql = "SELECT password FROM Admin WHERE email=:email"; $stmt = $this->con->prepare($sql); - $stmt->bindValue(':username', $username); + $stmt->bindValue(':email', $email); $stmt->execute(); $result = $stmt->fetch(); return $result['password']; } -} \ No newline at end of file + + public function getUserId(string $email): int + { + $sql = "SELECT id FROM Admin WHERE email=:email"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':email', $email); + $stmt->execute(); + $result = $stmt->fetch(); + return $result['id']; + } + public function getUserByEmailAndPassword(string $email, string $password): User + { + $sql = "SELECT * FROM Admin WHERE email=:email AND password=:password"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); + $stmt->execute(); + $result = $stmt->fetch(); + return new User($result['id'], $result['email'], $result['password']); + } +} diff --git a/project/src/model/gateways/Connection.php b/project/src/model/gateways/Connection.php index 29a8f67..f1eee73 100755 --- a/project/src/model/gateways/Connection.php +++ b/project/src/model/gateways/Connection.php @@ -33,7 +33,7 @@ class Connection extends PDO { return $this->stmt->fetchall(); } - public function getOneResult() : array { + public function getOneResult() { return $this->stmt->fetch(); } } \ No newline at end of file diff --git a/project/src/model/gateways/DifficulteGateway.php b/project/src/model/gateways/DifficulteGateway.php new file mode 100755 index 0000000..f0cff3f --- /dev/null +++ b/project/src/model/gateways/DifficulteGateway.php @@ -0,0 +1,24 @@ +con = $con; + } + public function getAll() : array + { + $this->con->executeQuery("SELECT id, libelle FROM Difficulte;"); + return $this->con->getResults(); + } + + public function getFromId(int $id): array + { + $this->con->executeQuery("SELECT id, libelle FROM Difficulte WHERE id=:id;", + [':id' => [$id, $this->con::PARAM_INT]]); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/InviteGateway.php b/project/src/model/gateways/InviteGateway.php new file mode 100755 index 0000000..9404c60 --- /dev/null +++ b/project/src/model/gateways/InviteGateway.php @@ -0,0 +1,38 @@ +con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE idSession = :idSession;", + [":idSession" => [$idSession, $this->con::PARAM_STR]]); + return $this->con->getOneResult(); + } + + public function getFromId($id): array|bool + { + $this->con->executeQuery("SELECT idJoueur, pseudo, idSession FROM Invite JOIN Joueur ON id=idJoueur WHERE id = :id;", + [":id" => [$id, $this->con::PARAM_INT]]); + return $this->con->getOneResult(); + } + + public function insertInvite(string $pseudo, string $idSession): int{ + $row = $this->getFromIdSession($idSession); + if($row != false){ + throw new IdSessionDoubleException($row['idjoueur'], $row['idsession']); + }else{ + $id = $this->insertJoueur($pseudo); + $this->con->executeQuery("INSERT INTO Invite(idJoueur, idSession) VALUES(:id, :idSession);", + [":id" => [$id, $this->con::PARAM_INT], + ":idSession" => [$idSession, $this->con::PARAM_STR]]); + return $id; + } + } +} \ No newline at end of file diff --git a/project/src/model/gateways/JeuGateway.php b/project/src/model/gateways/JeuGateway.php new file mode 100755 index 0000000..0f3f74a --- /dev/null +++ b/project/src/model/gateways/JeuGateway.php @@ -0,0 +1,26 @@ +con = $con; + } + public function getAll() : array + { + $this->con->executeQuery("SELECT id, nom, nbrparties FROM Jeu;"); + return $this->con->getResults(); + } + + public function getFromId(int $id): array + { + $this->con->executeQuery("SELECT id, nom, nbrparties FROM Jeu WHERE id=:id;", + [':id' => [$id, $this->con::PARAM_INT]]); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/JoueurGateway.php b/project/src/model/gateways/JoueurGateway.php new file mode 100755 index 0000000..18e6055 --- /dev/null +++ b/project/src/model/gateways/JoueurGateway.php @@ -0,0 +1,39 @@ +con = $con; + } + + protected function getFromPseudo($pseudo): array|bool + { + $this->con->executeQuery("SELECT id, pseudo FROM Joueur WHERE pseudo = :pseudo;", + [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); + return $this->con->getOneResult(); + } + + protected function insertJoueur(string $pseudo): int{ + if($this->getFromPseudo($pseudo) != false){ + throw new PseudoDejaPrisException(); + }else{ + $this->con->executeQuery("INSERT INTO Joueur(pseudo) VALUES(:pseudo);", + [":pseudo" => [$pseudo, $this->con::PARAM_STR]]); + return $this->getFromPseudo($pseudo)["id"]; + } + } + + public function setPseudo(int $id, string $pseudo){ + if($this->getFromPseudo($pseudo) != false){ + throw new PseudoDejaPrisException(); + }else{ + $this->con->executeQuery("UPDATE Joueur SET pseudo=:pseudo WHERE id=:id", + [":pseudo" => [$pseudo, $this->con::PARAM_STR], + ":id" => [$id, $this->con::PARAM_INT]]); + } + } +} \ No newline at end of file diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php new file mode 100755 index 0000000..a863ea2 --- /dev/null +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -0,0 +1,18 @@ +con = $con; + } + + public function getRandom(): array|bool{ + $this->con->executeQuery( + "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;"); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/SexeGateway.php b/project/src/model/gateways/SexeGateway.php new file mode 100755 index 0000000..3a4e608 --- /dev/null +++ b/project/src/model/gateways/SexeGateway.php @@ -0,0 +1,19 @@ +con = $con; + } + + public function getFromId(int $id): array + { + $this->con->executeQuery("SELECT id, libelle FROM Sexe WHERE id=:id;", + [':id' => [$id, $this->con::PARAM_INT]]); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/ThematiqueGateway.php b/project/src/model/gateways/ThematiqueGateway.php new file mode 100755 index 0000000..deb64cf --- /dev/null +++ b/project/src/model/gateways/ThematiqueGateway.php @@ -0,0 +1,19 @@ +con = $con; + } + + public function getFromId(int $id): array + { + $this->con->executeQuery("SELECT id, libelle FROM Thematique WHERE id=:id;", + [':id' => [$id, $this->con::PARAM_INT]]); + return $this->con->getOneResult(); + } +} \ No newline at end of file diff --git a/project/src/model/gateways/UserGateway.php b/project/src/model/gateways/UserGateway.php index 5010d76..188418a 100755 --- a/project/src/model/gateways/UserGateway.php +++ b/project/src/model/gateways/UserGateway.php @@ -4,98 +4,107 @@ namespace model; class UserGateway { - private \PDO $con; + private Connection $con; private \PDOStatement $stmt; public function __construct(Connection $con) { $this->con=$con; } - public function login(string $username, string $password): bool + public function login(string $email, string $password): bool { - $sql = "SELECT * FROM user WHERE username=:username"; + $sql = "SELECT * FROM Utilisateur WHERE email=:email"; $this->con->executeQuery($sql, array( - ':username' => array($username, \PDO::PARAM_STR) + ':email' => array($email, \PDO::PARAM_STR) )); $result = $this->con->getOneResult(); - - if (!empty($result) && md5($password) == $result['password']) { - return true; + + if (!empty($result)) { + return password_verify($password,$result['password']); } return false; } - public function addUser(string $username, string $password): void + public function addUser(string $email, string $password): void { - $sql = "INSERT INTO user (username, password) VALUES (:username, :password)"; + $sql = "INSERT INTO utilisateur (email, password) VALUES (:email, :password)"; $stmt = $this->con->prepare($sql); - $stmt->bindValue(':username', $username); - $stmt->bindValue(':password', password_hash($password, 'md5')); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); $stmt->execute(); } public function deleteUser(int $id): void { - $sql = "DELETE FROM user WHERE id=:id"; + $sql = "DELETE FROM utilisateur WHERE id=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); } - public function updateUser(int $id, string $username, string $password): void + public function updateUser(int $id, string $email, string $password): void { - $sql = "UPDATE user SET username=:username, password=:password WHERE id=:id"; + $sql = "UPDATE utilisateur SET email=:email, password=:password WHERE id=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); - $stmt->bindValue(':username', $username); - $stmt->bindValue(':password', $password); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); $stmt->execute(); } public function getUser(int $id): User { - $sql = "SELECT * FROM user WHERE id=:id"; + $sql = "SELECT * FROM utilisateur WHERE id=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); $result = $stmt->fetch(); - return new User($result['id'], $result['username'], $result['password']); + return new User($result['id'], $result['email'], $result['password']); } public function getUsers(): array { - $sql = "SELECT * FROM user"; + $sql = "SELECT * FROM utilisateur"; $stmt = $this->con->prepare($sql); $stmt->execute(); $result = $stmt->fetchAll(); $users = []; foreach ($result as $user) { - $users[] = new User($user['id'], $user['username'], $user['password']); + $users[] = new User($user['id'], $user['email'], $user['password']); } return $users; } public function getHashedPasswordById(int $id): string { - $sql = "SELECT password FROM user WHERE id=:id"; + $sql = "SELECT password FROM utilisateur WHERE id=:id"; $stmt = $this->con->prepare($sql); $stmt->bindValue(':id', $id); $stmt->execute(); $result = $stmt->fetch(); return $result['password']; } - public function getUserId(string $username): int + public function getHashedPassword(int $email): string + { + $sql = "SELECT password FROM utilisateur WHERE email=:email"; + $stmt = $this->con->prepare($sql); + $stmt->bindValue(':email', $email); + $stmt->execute(); + $result = $stmt->fetch(); + return $result['password']; + } + public function getUserId(string $email): int { - $sql = "SELECT id FROM user WHERE username=:username"; + $sql = "SELECT id FROM utilisateur WHERE email=:email"; $stmt = $this->con->prepare($sql); - $stmt->bindValue(':username', $username); + $stmt->bindValue(':email', $email); $stmt->execute(); $result = $stmt->fetch(); return $result['id']; } - public function getUserByUsernameAndPassword(string $username, string $password): User + public function getUserByEmailAndPassword(string $email, string $password): User { - $sql = "SELECT * FROM user WHERE username=:username AND password=:password"; + $sql = "SELECT * FROM utilisateur WHERE email=:email AND password=:password"; $stmt = $this->con->prepare($sql); - $stmt->bindValue(':username', $username); - $stmt->bindValue(':password', $password); + $stmt->bindValue(':email', $email); + $stmt->bindValue(':password', password_hash($password, PASSWORD_DEFAULT)); $stmt->execute(); $result = $stmt->fetch(); - return new User($result['id'], $result['username'], $result['password']); + return new User($result['id'], $result['email'], $result['password']); } } diff --git a/project/src/model/mdl/MdlAdmin.php b/project/src/model/mdl/MdlAdmin.php new file mode 100755 index 0000000..55af3fb --- /dev/null +++ b/project/src/model/mdl/MdlAdmin.php @@ -0,0 +1,50 @@ +gw = new AdminGateway($this->con); + } + public function login(string $username, string $password): bool{ + return $this->gw->login($username, $password); + } + + public static function isAdmin() { + if(!isset($_SESSION['admin']) + || !$_SESSION['admin'] + || !isset($_SESSION['email']) + || $_SESSION['email'] == null) { + return false; + } + + return true; + } + + public static function logout() { + global $basePath; + + session_unset(); + session_destroy(); + $_SESSION = array(); + header("Location: ."); + } +/* + public function setPseudo(int $id, string $pseudo): User{ + $this->gw->setPseudo($id, $pseudo); + return $this->getFromId($id); + } + + public function insertInvite(string $pseudo, string $idSession): User{ + $id = $this->gw->insertInvite($pseudo, $idSession); + return $this->getFromId($id); + } + + public function getFromId(int $id): User{ + $row = $this->gw->getFromId($id); + return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']); + }*/ +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlBase.php b/project/src/model/mdl/MdlBase.php new file mode 100755 index 0000000..56064e5 --- /dev/null +++ b/project/src/model/mdl/MdlBase.php @@ -0,0 +1,13 @@ +con = new Connection($config["db"]["dsn"], $config["db"]["login"], $config["db"]["mdp"]); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlDifficulte.php b/project/src/model/mdl/MdlDifficulte.php new file mode 100755 index 0000000..ebe6546 --- /dev/null +++ b/project/src/model/mdl/MdlDifficulte.php @@ -0,0 +1,25 @@ +gw = new DifficulteGateway($this->con); + } + + public function getAll(): array{ + $listDifficulte = []; + foreach($this->gw->getAll() as $row){ + $listDifficulte[] = new Difficulte($row['id'], $row['libelle']); + } + return $listDifficulte; + } + + public function getFromId(int $id): Difficulte{ + $row = $this->gw->getFromId($id); + return new Difficulte($row['id'], $row['libelle']); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlInvite.php b/project/src/model/mdl/MdlInvite.php new file mode 100755 index 0000000..37642b9 --- /dev/null +++ b/project/src/model/mdl/MdlInvite.php @@ -0,0 +1,27 @@ +gw = new InviteGateway($this->con); + } + + public function setPseudo(int $id, string $pseudo): Invite{ + $this->gw->setPseudo($id, $pseudo); + return $this->getFromId($id); + } + + public function insertInvite(string $pseudo, string $idSession): Invite{ + $id = $this->gw->insertInvite($pseudo, $idSession); + return $this->getFromId($id); + } + + public function getFromId(int $id): Invite{ + $row = $this->gw->getFromId($id); + return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlJeu.php b/project/src/model/mdl/MdlJeu.php new file mode 100755 index 0000000..0c33a7d --- /dev/null +++ b/project/src/model/mdl/MdlJeu.php @@ -0,0 +1,25 @@ +gw = new JeuGateway($this->con); + } + + public function getAll(): array{ + $listJeu = []; + foreach($this->gw->getAll() as $row){ + $listJeu[] = new Jeu($row['id'], $row['nom'], $row['nbrparties']); + } + return $listJeu; + } + + public function getFromId(int $id): Jeu{ + $row = $this->gw->getFromId($id); + return new Jeu($row['id'], $row['nom'], $row['nbrparties']); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlPendu.php b/project/src/model/mdl/MdlPendu.php new file mode 100755 index 0000000..63b15f2 --- /dev/null +++ b/project/src/model/mdl/MdlPendu.php @@ -0,0 +1,85 @@ +scientifiqueATrouver = $scientifiqueATrouver; + $this->aTrouver = strtr($scientifiqueATrouver->getPrenom()." ".$scientifiqueATrouver->getNom(), 'áàâäãåçéèêëíìîïñóòôöõúùûüýÿ', 'aaaaaaceeeeiiiinooooouuuuyy'); #suppression des accents + $this->nbFail = 0; + $this->nbTours = 0; + $this->lettreExceptees = [' ', '-']; + $this->lettreUtilisees = []; + } + + public function jouerLettre(string $lettre): string{ + $lettre = strtolower($lettre); + if(strlen($lettre) != 1){ throw new ValidationException("Veuillez fournir une seule lettre");} + if(!ctype_alpha($lettre)){ throw new ValidationException("Veuillez fournir une caractère alphabétique");} + if(in_array($lettre, $this->lettreUtilisees)){ throw new ValidationException("Vous avez déjà joué cette lettre");} + $this->nbTours += 1; + + if(!str_contains($this->aTrouver, $lettre)){ + $this->nbFail += 1; + } + $this->lettreUtilisees[] = $lettre; + return $this->getDecouvert(); + } + + public function getScientifique(): Scientifique + { + return $this->scientifiqueATrouver; + } + + public function getLettreUtilisees(): array{ + return $this->lettreUtilisees; + } + + public function getATrouver(): string + { + return $this->aTrouver; + } + + public function getDecouvert(): string + { + $decouvert = ''; + foreach(str_split($this->aTrouver) as $lettre){ + if(in_array(strtolower($lettre), $this->lettreUtilisees) || in_array(strtolower($lettre), $this->lettreExceptees)){ + $decouvert.=$lettre; + }else{ + $decouvert.="_"; + } + } + return $decouvert; + } + + public function getNbTours():int{ + return $this->nbTours; + } + + public function getNbFails():int{ + return $this->nbFail; + } + + public function getEssaisRestant():int{ + return $this::$nbFailsMax - $this->nbFail; + } + + public function aGagne(): bool{ + return $this->getDecouvert() == $this->getATrouver(); + } + + public function aPerdu(): bool{ + return $this->getEssaisRestant() <= 0; + } + +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlScientifique.php b/project/src/model/mdl/MdlScientifique.php new file mode 100755 index 0000000..6ea01da --- /dev/null +++ b/project/src/model/mdl/MdlScientifique.php @@ -0,0 +1,40 @@ +gw = new ScientifiqueGateway($this->con); + $this->mdlSexe = new MdlSexe(); + $this->mdlDifficulte = new MdlDifficulte(); + $this->mdlThematique = new MdlThematique(); + } + + public function getRandom(): Scientifique{ + $row = $this->gw->getRandom(); + if($row == false) throw new RuntimeException("Erreur aucun scientifique trouvé"); + $sexe = $this->mdlSexe->getFromId($row['idsexe']); + $difficulte = $this->mdlDifficulte->getFromId($row['iddifficulte']); + $thematique = $this->mdlThematique->getFromId($row['idthematique']); + + return new Scientifique($row['id'], + $row['nom'], + $row['prenom'], + $row['photo'], + new DateTime($row['datenaissance']), + $row['descriptif'], + $row['ratiotrouvee'], + $thematique, + $difficulte, + $sexe); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlSexe.php b/project/src/model/mdl/MdlSexe.php new file mode 100755 index 0000000..bc9cf40 --- /dev/null +++ b/project/src/model/mdl/MdlSexe.php @@ -0,0 +1,17 @@ +gw = new SexeGateway($this->con); + } + + public function getFromId(int $id): Sexe{ + $row = $this->gw->getFromId($id); + return new Sexe($row['id'], $row['libelle']); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlThematique.php b/project/src/model/mdl/MdlThematique.php new file mode 100755 index 0000000..d09f2ca --- /dev/null +++ b/project/src/model/mdl/MdlThematique.php @@ -0,0 +1,17 @@ +gw = new ThematiqueGateway($this->con); + } + + public function getFromId(int $id): Thematique{ + $row = $this->gw->getFromId($id); + return new Thematique($row['id'], $row['libelle']); + } +} \ No newline at end of file diff --git a/project/src/model/mdl/MdlUser.php b/project/src/model/mdl/MdlUser.php new file mode 100755 index 0000000..7693ed5 --- /dev/null +++ b/project/src/model/mdl/MdlUser.php @@ -0,0 +1,30 @@ +gw = new UserGateway($this->con); + } + public function login(string $username, string $password): bool{ + return $this->gw->login($username, $password); + } +/* + public function setPseudo(int $id, string $pseudo): User{ + $this->gw->setPseudo($id, $pseudo); + return $this->getFromId($id); + } + + public function insertInvite(string $pseudo, string $idSession): User{ + $id = $this->gw->insertInvite($pseudo, $idSession); + return $this->getFromId($id); + } + + public function getFromId(int $id): User{ + $row = $this->gw->getFromId($id); + return new Invite($row['idjoueur'], $row['pseudo'], $row['idsession']); + }*/ +} \ No newline at end of file diff --git a/project/src/model/metier/ConfigurationJeu.php b/project/src/model/metier/ConfigurationJeu.php new file mode 100755 index 0000000..de00913 --- /dev/null +++ b/project/src/model/metier/ConfigurationJeu.php @@ -0,0 +1,21 @@ +jeu = $jeu; + $this->difficulte = $difficulte; + } + + public function getDifficulte(): Difficulte{ + return $this->difficulte; + } + + public function getJeu(): Jeu{ + return $this->jeu; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Difficulte.php b/project/src/model/metier/Difficulte.php new file mode 100755 index 0000000..838d89a --- /dev/null +++ b/project/src/model/metier/Difficulte.php @@ -0,0 +1,33 @@ +id=$id; + $this->libelle=$libelle; + } + + /** + * @return int + */ + public function getId(): int{ + return $this->id; + } + + /** + * @return string + */ + public function getLibelle(): string{ + return $this->libelle; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Invite.php b/project/src/model/metier/Invite.php new file mode 100755 index 0000000..3e33d72 --- /dev/null +++ b/project/src/model/metier/Invite.php @@ -0,0 +1,18 @@ +idSession = $idSession; + } + + public function getIdSession(): string + { + return $this->idSession; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Jeu.php b/project/src/model/metier/Jeu.php new file mode 100755 index 0000000..89c9161 --- /dev/null +++ b/project/src/model/metier/Jeu.php @@ -0,0 +1,51 @@ +id=$id; + $this->nom=$nom; + $this->nbrParties=$nbrParties; + } + + /** + * @return int + */ + public function getId(): int{ + return $this->id; + } + + /** + * @return string + */ + public function getNom(): string{ + return $this->nom; + } + + /** + * @return int + */ + public function getNbParties():int{ + return $this->nbrParties; + } + + /** + * @return int + */ + public function incrementNbParties(): int{ + $this->nbrParties += 1; + return $this->nbrParties; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Joueur.php b/project/src/model/metier/Joueur.php new file mode 100755 index 0000000..57f67c1 --- /dev/null +++ b/project/src/model/metier/Joueur.php @@ -0,0 +1,24 @@ +id=$id; + $this->pseudo=$pseudo; + } + + public function getId(): int + { + return $this->id; + } + + public function getPseudo(): String + { + return $this->pseudo; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Scientifique.php b/project/src/model/metier/Scientifique.php new file mode 100755 index 0000000..29eff43 --- /dev/null +++ b/project/src/model/metier/Scientifique.php @@ -0,0 +1,132 @@ +id = $id; + $this->nom = $nom; + $this->prenom = $prenom; + $this->photo = $photo; + $this->ratioTrouvee = $ratioTrouvee; + $this->descriptif = $descriptif; + $this->dateNaiss = $dateNaiss; + $this->thematique = $thematique; + $this->difficulte = $difficulte; + $this->sexe = $sexe; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return string + */ + public function getNom(): string + { + return $this->nom; + } + + /** + * @return string + */ + public function getPrenom(): string + { + return $this->prenom; + } + + /** + * @return string + */ + public function getPhoto(): string + { + return $this->photo; + } + + /** + * @return string + */ + public function getDescriptif(): string + { + return $this->descriptif; + } + + /** + * @return DateTime + */ + public function getDateNaiss(): DateTime + { + return $this->dateNaiss; + } + + /** + * @return float + */ + public function getRatioTrouvee(): float + { + return $this->ratioTrouvee; + } + + /** + * @return Thematique + */ + public function getThematique(): Thematique + { + return $this->thematique; + } + + /** + * @return Difficulte + */ + public function getDifficulte(): Difficulte + { + return $this->difficulte; + } + + /** + * @return Sexe + */ + public function getSexe(): Sexe + { + return $this->sexe; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Sexe.php b/project/src/model/metier/Sexe.php new file mode 100755 index 0000000..86e6f89 --- /dev/null +++ b/project/src/model/metier/Sexe.php @@ -0,0 +1,25 @@ +id=$id; + $this->libelle=$libelle; + } + + public function getId():int + { + return $this->id; + } + + public function getLibelle(): string + { + return $this->libelle; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Thematique.php b/project/src/model/metier/Thematique.php new file mode 100755 index 0000000..7258408 --- /dev/null +++ b/project/src/model/metier/Thematique.php @@ -0,0 +1,25 @@ +id=$id; + $this->libelle=$libelle; + } + + public function getId():int + { + return $this->id; + } + + public function getLibelle(): string + { + return $this->libelle; + } +} \ No newline at end of file diff --git a/project/src/model/metier/Utilisateur.php b/project/src/model/metier/Utilisateur.php new file mode 100755 index 0000000..9cbdbd1 --- /dev/null +++ b/project/src/model/metier/Utilisateur.php @@ -0,0 +1,25 @@ +email = $email; + $this->motDePasse = $motDePasse; + } + + public function getEmail(): string + { + return $this->email; + } + + public function getMotDePasse(): string + { + return $this->motDePasse; + } +} \ No newline at end of file diff --git a/project/src/templates/accueil.html b/project/src/templates/accueil.html index a747535..eab2fe2 100755 --- a/project/src/templates/accueil.html +++ b/project/src/templates/accueil.html @@ -14,9 +14,14 @@

Bienvenue sur Mini-Jeux

- {% if dVue.info is defined %} -

{{dVue.info}}

+ + {% if dVue.nomJeu is defined %} +

Jeu selectionné : {{dVue.nomJeu}}

{% endif %} + {% if dVue.libelleDifficulte is defined %} +

Difficulte selectionné : {{dVue.libelleDifficulte}}

+ {% endif %} + {% if dVue.pseudo is defined %}

{{dVue.pseudo}}

@@ -26,8 +31,8 @@



- Rejoindre une partie - Créer une partie + Rejoindre une partie + Créer une partie
diff --git a/project/src/templates/create.html b/project/src/templates/create.html index bfb8ba3..cfbc19c 100755 --- a/project/src/templates/create.html +++ b/project/src/templates/create.html @@ -27,19 +27,37 @@
Mini-jeux disponibles - {% if dVueCreate is defined %} - {% for value in dVueCreate %} -
- - -
- {% endfor %} + {% if dVueErreur|length > 0 %} +
+
Erreur :
+ {% for erreur in dVueErreur %} +

{{erreur}}

+ {% endfor %} +
{% endif %} + {% if dVueCreate is defined %} + {% if dVueCreate["jeux"] is defined %} + {% for value in dVueCreate["jeux"] %} +
+ + +
+ {% endfor %} + {% endif %}
+ + {% if dVueCreate["difficultes"] is defined %} + + + {% endif %} - - + {% endif %} +
diff --git a/project/src/templates/join.html b/project/src/templates/join.html index ab9f92d..bb1816f 100755 --- a/project/src/templates/join.html +++ b/project/src/templates/join.html @@ -11,8 +11,8 @@

Merci de vous munir de votre code de partie et de l'entrer dans le champ ci-dessous

- - + +
diff --git a/project/src/templates/pendu.html b/project/src/templates/pendu.html new file mode 100755 index 0000000..0860aea --- /dev/null +++ b/project/src/templates/pendu.html @@ -0,0 +1,67 @@ + + + + + Pendu + + + + + +


+ +
+

+
+
+ {% if dVue.decouvert is defined %} +
+

+ {{dVue.decouvert}} +

+
+
+ {% endif %} + {% if dVue.essaisRestant is defined %} +

Il vous reste {{dVue.essaisRestant}} essais

+ {% endif %} + {% if dVue.lettresUtilisees is defined %} +
Lettres utilisées
+
+ {%for lettre in dVue.lettresUtilisees %} + {{lettre}}  + {% endfor %} +
+ {% endif %} + Votre lettre + {% if dVueErreur|length > 0 %} +
+
Erreur :
+ {% for erreur in dVueErreur %} +

{{erreur}}

+ {% endfor %} +
+ {% endif %} +
+ +
+
+ + +
+
+ + + + \ No newline at end of file diff --git a/project/src/templates/penduScore.html b/project/src/templates/penduScore.html new file mode 100755 index 0000000..f771300 --- /dev/null +++ b/project/src/templates/penduScore.html @@ -0,0 +1,49 @@ + + + + + Pendu - Score + + + + + +


+ +
+ {% if dVue.messageScore is defined %} +

{{dVue.messageScore}}

+ {% endif %} + + {% if dVue.nbTours is defined and dVue.nbFails is defined %} +

Vous avez fais {{dVue.nbTours}} essais et {{dVue.nbFails}} erreur(s)

+ {% endif %} + + {% if dVue.scientifique is defined %} +

Le scientifique a trouvé été {{dVue.scientifique.prenom}} {{dVue.scientifique.nom}}

+
+

Voici quelques informations à son sujet

+

Né(e) le : {{dVue.scientifique.dateNaiss}}

+

Sexe : {{dVue.scientifique.sexe}}

+

Domaine : {{dVue.scientifique.thematique}}

+

{{dVue.scientifique.descriptif}}

+
+ {% endif %} + + Retour à l'accueil +
+ + + + \ No newline at end of file diff --git a/project/src/templates/pseudo.html b/project/src/templates/pseudo.html new file mode 100755 index 0000000..b350bcf --- /dev/null +++ b/project/src/templates/pseudo.html @@ -0,0 +1,48 @@ + + + + + Saisir Pseudo + + + + + +


+ +
+

+
+
+ Veuillez choisir votre pseudo + {% if dVueErreur|length > 0 %} +
+
Erreur :
+ {% for erreur in dVueErreur %} +

{{erreur}}

+ {% endfor %} +
+ {% endif %} +
+ +
+
+ + +
+
+ + + + \ No newline at end of file diff --git a/project/src/vendor/autoload.php b/project/src/vendor/autoload.php index ebb04bd..040d665 100755 --- a/project/src/vendor/autoload.php +++ b/project/src/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34::getLoader(); +return ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f::getLoader(); diff --git a/project/src/vendor/composer/autoload_psr4.php b/project/src/vendor/composer/autoload_psr4.php index b3c8b1c..c7583e9 100755 --- a/project/src/vendor/composer/autoload_psr4.php +++ b/project/src/vendor/composer/autoload_psr4.php @@ -6,7 +6,7 @@ $vendorDir = dirname(__DIR__); $baseDir = dirname($vendorDir); return array( - 'model\\' => array($baseDir . '/model', $baseDir . '/model/gateways', $baseDir . '/model/metier'), + 'model\\' => array($baseDir . '/model', $baseDir . '/model/mdl', $baseDir . '/model/gateways', $baseDir . '/model/metier', $baseDir . '/model/exception'), 'controller\\' => array($baseDir . '/controller'), 'config\\' => array($baseDir . '/config'), 'Twig\\' => array($vendorDir . '/twig/twig/src'), diff --git a/project/src/vendor/composer/autoload_real.php b/project/src/vendor/composer/autoload_real.php index 1cc13ac..708bec9 100755 --- a/project/src/vendor/composer/autoload_real.php +++ b/project/src/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34 +class ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f { private static $loader; @@ -24,16 +24,16 @@ class ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34 require __DIR__ . '/platform_check.php'; - spl_autoload_register(array('ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit6539a3b2ab32d0f1df8933f4838b0c34', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit8ac61264e1d011c0b663d8c3dbdfc99f', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::getInitializer($loader)); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/project/src/vendor/composer/autoload_static.php b/project/src/vendor/composer/autoload_static.php index bea08ea..b009418 100755 --- a/project/src/vendor/composer/autoload_static.php +++ b/project/src/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34 +class ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f { public static $files = array ( '320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php', @@ -36,8 +36,10 @@ class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34 'model\\' => array ( 0 => __DIR__ . '/../..' . '/model', - 1 => __DIR__ . '/../..' . '/model/gateways', - 2 => __DIR__ . '/../..' . '/model/metier', + 1 => __DIR__ . '/../..' . '/model/mdl', + 2 => __DIR__ . '/../..' . '/model/gateways', + 3 => __DIR__ . '/../..' . '/model/metier', + 4 => __DIR__ . '/../..' . '/model/exception', ), 'controller\\' => array ( @@ -69,9 +71,9 @@ class ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit6539a3b2ab32d0f1df8933f4838b0c34::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit8ac61264e1d011c0b663d8c3dbdfc99f::$classMap; }, null, ClassLoader::class); } diff --git a/project/src/vendor/composer/installed.json b/project/src/vendor/composer/installed.json index 3179538..7f05e85 100755 --- a/project/src/vendor/composer/installed.json +++ b/project/src/vendor/composer/installed.json @@ -234,6 +234,59 @@ ], "install-path": "../symfony/polyfill-mbstring" }, + { + "name": "twbs/bootstrap", + "version": "v5.3.2", + "version_normalized": "5.3.2.0", + "source": { + "type": "git", + "url": "https://github.com/twbs/bootstrap.git", + "reference": "344e912d04b5b6a04482113eff20ab416ff01048" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twbs/bootstrap/zipball/344e912d04b5b6a04482113eff20ab416ff01048", + "reference": "344e912d04b5b6a04482113eff20ab416ff01048", + "shasum": "" + }, + "replace": { + "twitter/bootstrap": "self.version" + }, + "time": "2023-09-14T14:19:27+00:00", + "type": "library", + "installation-source": "dist", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Mark Otto", + "email": "markdotto@gmail.com" + }, + { + "name": "Jacob Thornton", + "email": "jacobthornton@gmail.com" + } + ], + "description": "The most popular front-end framework for developing responsive, mobile first projects on the web.", + "homepage": "https://getbootstrap.com/", + "keywords": [ + "JS", + "css", + "framework", + "front-end", + "mobile-first", + "responsive", + "sass", + "web" + ], + "support": { + "issues": "https://github.com/twbs/bootstrap/issues", + "source": "https://github.com/twbs/bootstrap/tree/v5.3.2" + }, + "install-path": "../twbs/bootstrap" + }, { "name": "twig/twig", "version": "v3.7.1", diff --git a/project/src/vendor/composer/installed.php b/project/src/vendor/composer/installed.php index ff3c7c2..8e75056 100755 --- a/project/src/vendor/composer/installed.php +++ b/project/src/vendor/composer/installed.php @@ -3,7 +3,7 @@ 'name' => '__root__', 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'b73e92d0b63a25bee137d61b716ec77ce0da68b8', + 'reference' => '4faf5aeca4c05c9018b964ff1861f0cf14a736b4', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -13,7 +13,7 @@ '__root__' => array( 'pretty_version' => 'dev-master', 'version' => 'dev-master', - 'reference' => 'b73e92d0b63a25bee137d61b716ec77ce0da68b8', + 'reference' => '4faf5aeca4c05c9018b964ff1861f0cf14a736b4', 'type' => 'library', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -46,6 +46,15 @@ 'aliases' => array(), 'dev_requirement' => false, ), + 'twbs/bootstrap' => array( + 'pretty_version' => 'v5.3.2', + 'version' => '5.3.2.0', + 'reference' => '344e912d04b5b6a04482113eff20ab416ff01048', + 'type' => 'library', + 'install_path' => __DIR__ . '/../twbs/bootstrap', + 'aliases' => array(), + 'dev_requirement' => false, + ), 'twig/twig' => array( 'pretty_version' => 'v3.7.1', 'version' => '3.7.1.0', @@ -55,5 +64,11 @@ 'aliases' => array(), 'dev_requirement' => false, ), + 'twitter/bootstrap' => array( + 'dev_requirement' => false, + 'replaced' => array( + 0 => 'v5.3.2', + ), + ), ), ); diff --git a/project/src/vendor/symfony/polyfill-ctype b/project/src/vendor/symfony/polyfill-ctype deleted file mode 160000 index ea208ce..0000000 --- a/project/src/vendor/symfony/polyfill-ctype +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb diff --git a/project/src/vendor/symfony/polyfill-mbstring b/project/src/vendor/symfony/polyfill-mbstring deleted file mode 160000 index 42292d9..0000000 --- a/project/src/vendor/symfony/polyfill-mbstring +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 42292d99c55abe617799667f454222c54c60e229 diff --git a/project/src/vendor/twig/twig b/project/src/vendor/twig/twig deleted file mode 160000 index a0ce373..0000000 --- a/project/src/vendor/twig/twig +++ /dev/null @@ -1 +0,0 @@ -Subproject commit a0ce373a0ca3bf6c64b9e3e2124aca502ba39554