From 9fa238e0934db2ac35791c084ddf4a78df9c7040 Mon Sep 17 00:00:00 2001 From: Jeremy DUCOURTHIAL Date: Tue, 21 Nov 2023 14:06:11 +0100 Subject: [PATCH] feat : Connexion + add Player --- .../ControllerAdminAdministrators.php | 4 +- .../controllers/ControllerAdminChapters.php | 4 +- .../controllers/ControllerAdminQuestions.php | 4 +- Website/controllers/ControllerUser.php | 42 +++++++++++- Website/controllers/ControllerUserLobby.php | 2 +- Website/controllers/ControllerUserPlayers.php | 18 +++--- Website/controllers/FrontController.php | 6 +- Website/gateways/GatewayPlayer.php | 7 +- Website/index.php | 1 + Website/models/ModelPlayer.php | 6 ++ Website/templates/loginPlayer.twig | 34 +++++++++- Website/templates/userPlayerModal.twig | 64 +++++++++++++++++++ Website/templates/userStatus.twig | 16 +++++ Website/usages/Config.php | 3 +- 14 files changed, 182 insertions(+), 29 deletions(-) create mode 100644 Website/templates/userPlayerModal.twig create mode 100644 Website/templates/userStatus.twig diff --git a/Website/controllers/ControllerAdminAdministrators.php b/Website/controllers/ControllerAdminAdministrators.php index 1f6b0b3..244f1a5 100644 --- a/Website/controllers/ControllerAdminAdministrators.php +++ b/Website/controllers/ControllerAdminAdministrators.php @@ -9,7 +9,7 @@ class ControllerAdminAdministrators function __construct() { - global $dns, $user, $pass, $vues, $twig; + global $vues, $twig; session_start(); try { @@ -26,7 +26,7 @@ class ControllerAdminAdministrators ]); } else { - header("Location:/login"); + header("Location:/loginAdmin"); } } catch (PDOException $e) { // Gérez les erreurs PDO ici diff --git a/Website/controllers/ControllerAdminChapters.php b/Website/controllers/ControllerAdminChapters.php index 43beeed..25a8181 100644 --- a/Website/controllers/ControllerAdminChapters.php +++ b/Website/controllers/ControllerAdminChapters.php @@ -9,7 +9,7 @@ class ControllerAdminChapters function __construct() { - global $dns, $user, $pass, $vues, $twig; + global $vues, $twig; session_start(); try { if($_SESSION["idAdminConnected"] != null){ @@ -25,7 +25,7 @@ class ControllerAdminChapters ]); } else { - header("Location:/login"); + header("Location:/loginAdmin"); } } catch (PDOException $e) { // Gérez les erreurs PDO ici diff --git a/Website/controllers/ControllerAdminQuestions.php b/Website/controllers/ControllerAdminQuestions.php index ed4c1a3..46e0363 100644 --- a/Website/controllers/ControllerAdminQuestions.php +++ b/Website/controllers/ControllerAdminQuestions.php @@ -11,7 +11,7 @@ class ControllerAdminQuestions function __construct() { - global $dns, $user, $pass, $vues, $twig; + global $vues, $twig; session_start(); try { if ($_SESSION["idAdminConnected"] != null) { @@ -30,7 +30,7 @@ class ControllerAdminQuestions 'chapters' => $chapters, ]); } else { - header("Location:/login"); + header("Location:/loginAdmin"); } } catch (PDOException $e) { // Gérez les erreurs PDO ici diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index 61f16a0..b79147c 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -39,6 +39,7 @@ class ControllerUser { echo $this->twig->render($this->vues["home"]); } + function themeChoice() { $chapters = $this->mdChapter->getChapters(); @@ -46,6 +47,7 @@ class ControllerUser 'chapters' => $chapters, ]); } + function singleplayer() { echo $this->twig->render($this->vues["singleplayer"]); @@ -67,7 +69,7 @@ class ControllerUser function loginPlayer() { - echo $this->twig->render($this->vues["loginAdmin"], [ + echo $this->twig->render($this->vues["loginPlayer"], [ 'error' => $_SESSION["error"], ]); @@ -90,7 +92,27 @@ class ControllerUser header("Location:/admin/administrators"); } else { $_SESSION["error"] = "utilisateur introuvable."; - header("Location:/login"); + header("Location:/loginAdmin"); + } + } + + function verifyPlayer() + { + $nickname = $_POST['nickname']; + $password = $_POST['password']; + + $Player = [ + 'nickname' => $nickname, + 'password' => $password, + ]; + + $PlayerIsOk = $this->mdPlayer->verifyPlayer($Player); + if ($PlayerIsOk != null) { + $_SESSION["idPlayerConnected"] = $PlayerIsOk; + header("Location:/userStatus"); + } else { + $_SESSION["error"] = "utilisateur introuvable."; + header("Location:/loginPlayer"); } } @@ -189,6 +211,22 @@ class ControllerUser } } } + + function userStatus(){ + if($_SESSION["idPlayerConnected"] != null){ + + //$this->mdAdministrator = new ModelAdministrator(); + + //$administrators = $this->mdAdministrator->getAdministrators(); + + echo $this->twig->render($this->vues["userStatus"]); + + } + else { + header("Location:/loginPlayer"); + } + } + function passer() { $numQuestion = $_POST["numQuestion"]; diff --git a/Website/controllers/ControllerUserLobby.php b/Website/controllers/ControllerUserLobby.php index f9bf141..7e81d03 100644 --- a/Website/controllers/ControllerUserLobby.php +++ b/Website/controllers/ControllerUserLobby.php @@ -9,7 +9,7 @@ class ControllerUserLobby function __construct() { - global $dns, $user, $pass, $vues, $twig; + global $vues, $twig; session_start(); try { $this->twig =$twig; diff --git a/Website/controllers/ControllerUserPlayers.php b/Website/controllers/ControllerUserPlayers.php index 14434cb..e11037d 100644 --- a/Website/controllers/ControllerUserPlayers.php +++ b/Website/controllers/ControllerUserPlayers.php @@ -9,18 +9,18 @@ class ControllerUserPlayers function __construct() { - global $dns, $user, $pass, $vues, $twig; + global $vues, $twig; session_start(); try { - if($_SESSION["idAdminConnected"] != null){ + if($_SESSION["idPlayerConnected"] != null){ $this->twig =$twig; $this->vues = $vues; $this->mdPlayer = new ModelPlayer(); } else { - header("Location:/login"); + header("Location:/loginPlayer"); } } catch (PDOException $e) { // Gérez les erreurs PDO ici @@ -30,28 +30,28 @@ class ControllerUserPlayers } function delete($param) { - $this->mdPlayer->deleteAdministratorByID($param["id"]); + $this->mdPlayer->deletePlayerByID($param["id"]); header("Location:/admin/administrators"); } function add($param) { - $username = $_POST['username']; + $nickname = $_POST['nickname']; $password = $_POST['password']; $Player = [ - 'username' => $username, + 'nickname' => $nickname, 'password' => $password, ]; - $this->mdPlayer->addAdministrator($Player); + $this->mdPlayer->addPlayer($Player); header("Location:/loginPlayer"); } function updatemodal($param) { - $administrator = $this->mdPlayer->getAdministratorByID($param["id"]); + $player = $this->mdPlayer->getPlayerByID($param["id"]); echo $this->twig->render($this->vues["adminAdministratorsModal"], [ 'administrator' => $administrator, @@ -69,7 +69,7 @@ class ControllerUserPlayers 'password' => $password, ]; - $this->mdPlayer->updateAdministrator($id,$Admin); + $this->mdPlayer->updatePlayer($id,$Admin); header("Location:/admin/administrators"); } diff --git a/Website/controllers/FrontController.php b/Website/controllers/FrontController.php index 4788dd5..01dc47f 100755 --- a/Website/controllers/FrontController.php +++ b/Website/controllers/FrontController.php @@ -3,7 +3,7 @@ class FrontController { function __construct() { - global $dsn, $user, $pass, $vues; + global $vues; try { // Initialize AltoRouter @@ -25,8 +25,8 @@ class FrontController $router->map('GET', '/admin/questions', 'ControllerAdminQuestions'); $router->map('POST', '/admin/questions/[a:action]', 'ControllerAdminQuestions'); $router->map('GET', '/admin/questions/[a:action]/[i:id]', 'ControllerAdminQuestions'); - $router->map('POST', '/user/players/[a:action]', 'ControllerAdminQuestions'); - $router->map('GET', '/user/players/[a:action]/[i:id]', 'ControllerAdminQuestions'); + $router->map('POST', '/user/players/[a:action]', 'ControllerUserPlayers'); + $router->map('GET', '/user/players/[a:action]/[i:id]', 'ControllerUserPlayers'); // Match the current request $match = $router->match(); diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php index e323adb..b804021 100755 --- a/Website/gateways/GatewayPlayer.php +++ b/Website/gateways/GatewayPlayer.php @@ -12,13 +12,12 @@ class GatewayPlayer public function addPlayer($player) { - $query = "insert into players(id,nickname,hashedPassword) values (:id,:nickname,:hashedPassword);"; + $query = "insert into players(nickname,password) values (:nickname,:password);"; $this->con->executeQuery( $query, array( - ':id' => array($player->getId(), PDO::PARAM_INT), ':nickname' => array($player['nickname'], PDO::PARAM_STR), - ':hashedPassword' => array($player['hashedPassword'], PDO::PARAM_STR) + ':password' => array(md5($player['password']), PDO::PARAM_STR) ) ); } @@ -85,7 +84,7 @@ class GatewayPlayer $query, array( ':nickname' => array($player['nickname'], PDO::PARAM_STR), - ':password' => array($player['password'], PDO::PARAM_STR) + ':password' => array(md5($player['password']), PDO::PARAM_STR) ) ); $results = $this->con->getResults(); diff --git a/Website/index.php b/Website/index.php index 76806ae..54200b5 100755 --- a/Website/index.php +++ b/Website/index.php @@ -2,6 +2,7 @@ //chargement config require_once(__DIR__ . '/usages/Config.php'); +require_once(__DIR__ . '/usages/Config_DB.php'); //chargement for twig require __DIR__ . '/vendor/autoload.php'; diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index fe9effe..f84cc96 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -14,6 +14,12 @@ class ModelPlayer $this->gwPlayer->addPlayer($player); } + public function verifyPlayer($player) + { + $playerId = $this->gwPlayer->verifyPlayer($player); + return $playerId; + } + public function getPlayerByID($id) { $playerDataArray = $this->gwPlayer->getPlayerByID($id); diff --git a/Website/templates/loginPlayer.twig b/Website/templates/loginPlayer.twig index b20d194..4c3fb1a 100644 --- a/Website/templates/loginPlayer.twig +++ b/Website/templates/loginPlayer.twig @@ -15,20 +15,48 @@

Connexion

- - + +
- S'inscrire +

{{error}}

+ + + + diff --git a/Website/templates/userPlayerModal.twig b/Website/templates/userPlayerModal.twig new file mode 100644 index 0000000..bc8013e --- /dev/null +++ b/Website/templates/userPlayerModal.twig @@ -0,0 +1,64 @@ + + + + Maths Educ + + + + + + + + + + + + + + + diff --git a/Website/templates/userStatus.twig b/Website/templates/userStatus.twig new file mode 100644 index 0000000..199b039 --- /dev/null +++ b/Website/templates/userStatus.twig @@ -0,0 +1,16 @@ + + + + + Math'Educ + + + + + +
+
+

test

+
+ + \ No newline at end of file diff --git a/Website/usages/Config.php b/Website/usages/Config.php index 817fd76..e911d4b 100644 --- a/Website/usages/Config.php +++ b/Website/usages/Config.php @@ -10,6 +10,7 @@ $vues["home"]="home.twig"; $vues["connexion"]="connexion.twig"; $vues["themeChoice"]="themeChoice.twig"; $vues["loginAdmin"]="loginAdmin.twig"; +$vues["loginPlayer"]="loginPlayer.twig"; $vues["adminAdministrators"]="adminAdministrators.twig"; $vues["adminAdministratorsModal"]="adminAdministratorsModal.twig"; $vues["adminChapters"]="adminChapters.twig"; @@ -17,4 +18,4 @@ $vues["adminChaptersModal"]="adminChaptersModal.twig"; $vues["adminQuestions"]="adminQuestions.twig"; $vues["adminQuestionsModal"]="adminQuestionsModal.twig"; $vues["viewScore"]="viewScore.twig"; -$vues["lobby"]="lobby.twig"; \ No newline at end of file +$vues["userStatus"]="userStatus.twig"; \ No newline at end of file