From a3f5331abbc77694dbfbce62b80542bb1f07da84 Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Tue, 21 Nov 2023 15:46:06 +0100 Subject: [PATCH 1/4] feat : little verification --- .../ControllerAdminAdministrators.php | 67 ++++++++++++------- Website/gateways/GatewayAdministrator.php | 13 ++++ Website/models/ModelAdministrator.php | 5 ++ 3 files changed, 60 insertions(+), 25 deletions(-) diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index cc7bcf0..5f61fe3 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -19,19 +19,20 @@ class ControllerAdminAdministrators session_start(); try { - if($_SESSION["idAdminConnected"] != null){ - $this->twig =$twig; + if ($_SESSION["idAdminConnected"] != null) { + $this->twig = $twig; $this->vues = $vues; - + $this->mdAdministrator = new ModelAdministrator(); - + $administrators = $this->mdAdministrator->getAdministrators(); - + echo $twig->render($vues["adminAdministrators"], [ 'administrators' => $administrators, + 'error' => $_SESSION["error"], ]); - } - else { + $_SESSION["error"] = null; + } else { header("Location:/loginAdmin"); } } catch (PDOException $e) { @@ -41,27 +42,42 @@ class ControllerAdminAdministrators } } - function delete($param) { + function delete($param) + { $this->mdAdministrator->deleteAdministratorByID($param["id"]); header("Location:/admin/administrators"); } - function add($param) { - - $username = $_POST['username']; - $password = $_POST['password']; - - $Admin = [ - 'username' => $username, - 'password' => $password, - ]; - - $this->mdAdministrator->addAdministrator($Admin); - - header("Location:/admin/administrators"); + function add($param) + { + var_dump($_SERVER['REQUEST_METHOD'] !== 'POST'); + if ($_SERVER['REQUEST_METHOD'] !== 'POST') { + $_SESSION["error"]="Méthode non autorisée."; + } else { + $username = $_POST['username']; + $password = $_POST['password']; + $username = trim($_POST['username']); + $password = trim($_POST['password']); + var_dump(!isset($_POST['username']) || !isset($_POST['password']) || empty($username) || empty($password)); + if (!isset($username) || !isset($password) || empty($username) || empty($password)) { + $_SESSION["error"]="Veuillez remplir tous les champs."; + } else { + $Admin = [ + 'username' => $username, + 'password' => $password, + ]; + if ($this->mdAdministrator->verifyAdministratorByName($Admin) != null) { + $_SESSION["error"]="Cet admin existe déjà."; + } else { + $this->mdAdministrator->addAdministrator($Admin); + header("Location:/admin/administrators"); + } + } + } } - function updatemodal($param) { + function updatemodal($param) + { $administrator = $this->mdAdministrator->getAdministratorByID($param["id"]); @@ -70,7 +86,8 @@ class ControllerAdminAdministrators ]); } - function update($param) { + function update($param) + { $id = $_POST['id']; $username = $_POST['username']; @@ -81,8 +98,8 @@ class ControllerAdminAdministrators 'password' => $password, ]; - $this->mdAdministrator->updateAdministrator($id,$Admin); + $this->mdAdministrator->updateAdministrator($id, $Admin); header("Location:/admin/administrators"); } -} \ No newline at end of file +} diff --git a/Website/gateways/GatewayAdministrator.php b/Website/gateways/GatewayAdministrator.php index aa40056..ebc749f 100755 --- a/Website/gateways/GatewayAdministrator.php +++ b/Website/gateways/GatewayAdministrator.php @@ -87,6 +87,19 @@ class GatewayAdministrator ); $results = $this->con->getResults(); + return $results[0]; + } + public function verifyAdministratorByName($administrator) + { + $query = "SELECT administrators.id FROM administrators WHERE username = :username"; + $this->con->executeQuery( + $query, + array( + ':username' => array($administrator['username'], PDO::PARAM_STR), + ) + ); + $results = $this->con->getResults(); + return $results[0]; } } diff --git a/Website/models/ModelAdministrator.php b/Website/models/ModelAdministrator.php index 9d0b823..b0e2051 100644 --- a/Website/models/ModelAdministrator.php +++ b/Website/models/ModelAdministrator.php @@ -52,4 +52,9 @@ class ModelAdministrator $administratorsId = $this->gwAdministrator->verifyAdministrator($Administrator); return $administratorsId; } + public function verifyAdministratorByName($Administrator) + { + $administratorsId = $this->gwAdministrator->verifyAdministratorByName($Administrator); + return $administratorsId; + } } From c6f091387f6b8d60e87c0eed52fb25b213ec65d5 Mon Sep 17 00:00:00 2001 From: Jeremy DUCOURTHIAL Date: Tue, 21 Nov 2023 15:48:10 +0100 Subject: [PATCH 2/4] feat : base player --- Website/controllers/ControllerUser.php | 5 ++--- Website/templates/userStatus.twig | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 181bab2..a2a6ccc 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -239,12 +239,11 @@ class ControllerUser function userStatus(){ if($_SESSION["idPlayerConnected"] != null){ - //$this->mdAdministrator = new ModelAdministrator(); + //$this->mdPlayer = new ModelPlayer(); - //$administrators = $this->mdAdministrator->getAdministrators(); + //$player = $this->mdPlayer->getPlayerByID($_SESSION["idAdminConnected"]); echo $this->twig->render($this->vues["userStatus"]); - } else { header("Location:/loginPlayer"); diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 199b039..911d11d 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -11,6 +11,7 @@

test

+
\ No newline at end of file From 0ac96eecd2a0c7210dad5c91733f379b1a3fb9ce Mon Sep 17 00:00:00 2001 From: "yvan.calatayud" Date: Tue, 21 Nov 2023 17:11:04 +0100 Subject: [PATCH 3/4] style : design ++ --- Website/controllers/ControllerUser.php | 12 ++++++++- Website/templates/addquestions.twig | 1 - Website/templates/adminAdministrators.twig | 29 +++++++++++----------- Website/templates/adminChapters.twig | 28 +++++++++++---------- Website/templates/adminQuestions.twig | 28 +++++++++++---------- Website/templates/home.twig | 13 +++++++--- Website/templates/loginAdmin.twig | 7 +++++- Website/templates/loginPlayer.twig | 7 +++++- Website/templates/themeChoice.twig | 8 +++--- Website/templates/userStatus.twig | 5 ++++ 10 files changed, 88 insertions(+), 50 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 181bab2..00c7bcf 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -49,7 +49,9 @@ class ControllerUser function home() { - echo $this->twig->render($this->vues["home"]); + echo $this->twig->render($this->vues["home"], [ + 'idPlayerConnected' => $_SESSION["idPlayerConnected"] + ]); } function error() @@ -78,6 +80,10 @@ class ControllerUser function loginAdmin() { + if ($_SESSION["idAdminConnected"] != null){ + header("Location:/admin/administrators"); + } + echo $this->twig->render($this->vues["loginAdmin"], [ 'error' => $_SESSION["error"], ]); @@ -87,6 +93,10 @@ class ControllerUser function loginPlayer() { + if ($_SESSION["idPlayerConnected"] != null){ + header("Location:/userStatus"); + } + echo $this->twig->render($this->vues["loginPlayer"], [ 'error' => $_SESSION["error"], ]); diff --git a/Website/templates/addquestions.twig b/Website/templates/addquestions.twig index a6854eb..10dcc28 100644 --- a/Website/templates/addquestions.twig +++ b/Website/templates/addquestions.twig @@ -1,6 +1,5 @@ - diff --git a/Website/templates/adminAdministrators.twig b/Website/templates/adminAdministrators.twig index 228865d..a982a62 100644 --- a/Website/templates/adminAdministrators.twig +++ b/Website/templates/adminAdministrators.twig @@ -5,32 +5,33 @@ - - + - -
+ + +

Liste des administrators

-
- - +
+ ← Questions + + Chapitres →
diff --git a/Website/templates/adminChapters.twig b/Website/templates/adminChapters.twig index 934f0aa..10e4d53 100644 --- a/Website/templates/adminChapters.twig +++ b/Website/templates/adminChapters.twig @@ -6,31 +6,33 @@ - + - -
+ + +

Liste des chapitres

-
- - +
+ ← Administrateur + + Questions →
diff --git a/Website/templates/adminQuestions.twig b/Website/templates/adminQuestions.twig index 9faa79f..9d7e345 100644 --- a/Website/templates/adminQuestions.twig +++ b/Website/templates/adminQuestions.twig @@ -6,31 +6,33 @@ - + - -
+ + +

Liste des questions

-
- - +
+ ← Chapitres + + Administrateurs →
diff --git a/Website/templates/home.twig b/Website/templates/home.twig index 545af64..4bcb86c 100644 --- a/Website/templates/home.twig +++ b/Website/templates/home.twig @@ -1,6 +1,5 @@ - @@ -11,7 +10,15 @@
- CONNEXION + {% if idPlayerConnected == null %} + + CONNEXION + + {% else %} + + PROFIL + + {% endif %}
@@ -22,7 +29,7 @@
- +

MULTIJOUEUR diff --git a/Website/templates/loginAdmin.twig b/Website/templates/loginAdmin.twig index 76b8f60..bf15da8 100644 --- a/Website/templates/loginAdmin.twig +++ b/Website/templates/loginAdmin.twig @@ -6,7 +6,12 @@ - + +
diff --git a/Website/templates/loginPlayer.twig b/Website/templates/loginPlayer.twig index 2d3cf8d..29d8a75 100644 --- a/Website/templates/loginPlayer.twig +++ b/Website/templates/loginPlayer.twig @@ -6,7 +6,12 @@ - + +
diff --git a/Website/templates/themeChoice.twig b/Website/templates/themeChoice.twig index ece9297..1619111 100644 --- a/Website/templates/themeChoice.twig +++ b/Website/templates/themeChoice.twig @@ -11,9 +11,11 @@ - - Retour - +

Difficulte :

diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 199b039..cbcfccc 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -8,6 +8,11 @@ +

test

From d31c2c90f355446f56d9eebdd4866a0df88cdb86 Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Tue, 21 Nov 2023 17:24:21 +0100 Subject: [PATCH 4/4] feat : page user --- .../ControllerAdminAdministrators.php | 2 -- Website/controllers/ControllerUser.php | 33 +++++++++++-------- Website/gateways/GatewayJouer.php | 12 +++++++ Website/gateways/GatewayPlayer.php | 3 +- Website/models/ModelPlayer.php | 7 ++++ Website/templates/userPlayerModal.twig | 1 - Website/templates/userStatus.twig | 19 +++++++---- 7 files changed, 52 insertions(+), 25 deletions(-) diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index 5f61fe3..6c0ed8b 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -50,7 +50,6 @@ class ControllerAdminAdministrators function add($param) { - var_dump($_SERVER['REQUEST_METHOD'] !== 'POST'); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { $_SESSION["error"]="Méthode non autorisée."; } else { @@ -58,7 +57,6 @@ class ControllerAdminAdministrators $password = $_POST['password']; $username = trim($_POST['username']); $password = trim($_POST['password']); - var_dump(!isset($_POST['username']) || !isset($_POST['password']) || empty($username) || empty($password)); if (!isset($username) || !isset($password) || empty($username) || empty($password)) { $_SESSION["error"]="Veuillez remplir tous les champs."; } else { diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index f48710b..c1f99f6 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -94,6 +94,25 @@ class ControllerUser $_SESSION["error"] = ""; } + function userStatus(){ + if($_SESSION["idPlayerConnected"] != null){ + $this->mdPlayer = new ModelPlayer(); + $player = $this->mdPlayer->getPlayerByID($_SESSION["idPlayerConnected"]); + $maxscores = $this->mdPlayer->getMaxScoresWithChapter($player); + foreach ($maxscores as $maxscore) { + $maxscore["chapter"]=$this->mdChapter->getChapterByID($maxscore["idchapter"])->getName(); + } + echo $this->twig->render($this->vues["userStatus"], + [ + 'player' => $player, + 'maxscores' => $maxscores, + ]); + } + else { + header("Location:/loginPlayer"); + } + } + function verifyAdmin() { $username = $_POST['username']; @@ -241,20 +260,6 @@ class ControllerUser } } - function userStatus(){ - if($_SESSION["idPlayerConnected"] != null){ - - //$this->mdPlayer = new ModelPlayer(); - - //$player = $this->mdPlayer->getPlayerByID($_SESSION["idAdminConnected"]); - - echo $this->twig->render($this->vues["userStatus"]); - } - else { - header("Location:/loginPlayer"); - } - } - function passer() { $numQuestion = $_POST["numQuestion"]; diff --git a/Website/gateways/GatewayJouer.php b/Website/gateways/GatewayJouer.php index 151be1d..ae4b411 100644 --- a/Website/gateways/GatewayJouer.php +++ b/Website/gateways/GatewayJouer.php @@ -68,4 +68,16 @@ class GatewayJouer $results = $this->con->getResults(); return $results[0]; } + public function getMaxScoresWithChapter($player) + { + $query = "SELECT maxscore,idchapter FROM jouer WHERE idplayer = :idplayer;"; + $this->con->executeQuery( + $query, + array( + ':idplayer' => array($player->getId(), PDO::PARAM_STR) + ) + ); + $results = $this->con->getResults(); + return $results; + } } \ No newline at end of file diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php index 33d14b0..aa6615a 100755 --- a/Website/gateways/GatewayPlayer.php +++ b/Website/gateways/GatewayPlayer.php @@ -93,7 +93,6 @@ class GatewayPlayer ) ); $results = $this->con->getResults(); - - return $results[0]; + return $results[0][0]; } } diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index d579b04..6c92d43 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -32,6 +32,7 @@ class ModelPlayer { $playerDataArray = $this->gwPlayer->getPlayerByID($id); $player = new Player($playerDataArray["id"], $playerDataArray["nickname"], $playerDataArray["password"]); + return $player; } public function updatePlayer($id, $player) @@ -59,4 +60,10 @@ class ModelPlayer { $this->gwJouer->updateJouer($idPlayer, $idChapter, $jouer); } + + public function getMaxScoresWithChapter($player) + { + $maxScores = $this->gwJouer->getMaxScoresWithChapter($player); + return $maxScores; + } } diff --git a/Website/templates/userPlayerModal.twig b/Website/templates/userPlayerModal.twig index bc8013e..d2bfe8b 100644 --- a/Website/templates/userPlayerModal.twig +++ b/Website/templates/userPlayerModal.twig @@ -5,7 +5,6 @@ - diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig index 911d11d..c89e1e9 100644 --- a/Website/templates/userStatus.twig +++ b/Website/templates/userStatus.twig @@ -1,17 +1,24 @@ - - Math'Educ + Maths Educ + + - +
-
-

test

- +
+

Player Nickname :

+

{{ player.nickname }}

+ {% for maxscore in maxscores %} +
+

Maxscore pour le chapitre {{ maxscore["chapter"] }} :

+

{{ maxscore["maxscore"] }}

+
+ {% endfor %} \ No newline at end of file