From c6324b8357aad73184498dca88181c9d71a7f791 Mon Sep 17 00:00:00 2001 From: "jade.van_brabandt" Date: Wed, 22 Nov 2023 17:48:32 +0100 Subject: [PATCH] feat : I don't evne know what I did but fiexd thing --- Website/controllers/ControllerUser.php | 2 ++ Website/controllers/ControllerUserPlayers.php | 36 +++++++++---------- Website/gateways/GatewayAdministrator.php | 7 +++- Website/gateways/GatewayPlayer.php | 22 +++++++++++- Website/models/ModelPlayer.php | 6 +++- Website/templates/userPlayerModal.twig | 20 ++++------- Website/templates/userStatus.twig | 32 +++++++++++++++++ Website/usages/Config.php | 1 + 8 files changed, 90 insertions(+), 36 deletions(-) diff --git a/Website/controllers/ControllerUser.php b/Website/controllers/ControllerUser.php index eba6c3d..c346937 100644 --- a/Website/controllers/ControllerUser.php +++ b/Website/controllers/ControllerUser.php @@ -118,8 +118,10 @@ class ControllerUser [ 'player' => $player, 'maxscores' => $maxscores, + 'error' => $_SESSION["error"], ] ); + $_SESSION["error"]=null; } else { header("Location:/loginPlayer"); } diff --git a/Website/controllers/ControllerUserPlayers.php b/Website/controllers/ControllerUserPlayers.php index 41bbe7e..ca4c5e0 100644 --- a/Website/controllers/ControllerUserPlayers.php +++ b/Website/controllers/ControllerUserPlayers.php @@ -17,13 +17,11 @@ class ControllerUserPlayers { global $vues, $twig; session_start(); + $this->mdPlayer = new ModelPlayer(); try { - if($_SESSION["idPlayerConnected"] != null){ $this->twig =$twig; $this->vues = $vues; - - $this->mdPlayer = new ModelPlayer(); } else { header("Location:/loginPlayer"); @@ -37,11 +35,11 @@ class ControllerUserPlayers function delete($param) { $this->mdPlayer->deletePlayerByID($param["id"]); - header("Location:/admin/administrators"); + $_SESSION["idPlayerConnected"]=null; + header("Location:/"); } - function add($param) { - + public function add($param) { $nickname = $_POST['nickname']; $password = $_POST['password']; @@ -50,33 +48,31 @@ class ControllerUserPlayers 'password' => $password, ]; + var_dump($Player); + $this->mdPlayer->addPlayer($Player); header("Location:/loginPlayer"); } function updatemodal($param) { - + $player = $this->mdPlayer->getPlayerByID($param["id"]); - - echo $this->twig->render($this->vues["adminAdministratorsModal"], [ + echo $this->twig->render($this->vues["userPlayerModal"], [ 'player' => $player, ]); } function update($param) { - $id = $_POST['id']; - $username = $_POST['username']; $password = $_POST['password']; - - $Admin = [ - 'username' => $username, - 'password' => $password, - ]; - - $this->mdPlayer->updatePlayer($id,$Admin); - - header("Location:/admin/administrators"); + if (!isset($password) || empty($password) || !isset($id) || empty($id) || !is_numeric($id) || $id < 0 || empty(trim($password)) || empty(trim($id))) { + $_SESSION["error"] = "Veuillez remplir tous les champs correctement"; + var_dump($id,$password); + header("Location:/userStatus"); + } else { + $this->mdPlayer->updatePlayerPassword($id,$password); + header("Location:/userStatus"); + } } } \ No newline at end of file diff --git a/Website/gateways/GatewayAdministrator.php b/Website/gateways/GatewayAdministrator.php index ebc749f..8b44b2a 100755 --- a/Website/gateways/GatewayAdministrator.php +++ b/Website/gateways/GatewayAdministrator.php @@ -72,7 +72,12 @@ class GatewayAdministrator public function deleteAdministratorByID($id) { $query = "DELETE FROM administrators WHERE id = :id;"; - $this->con->executeQuery($query, array(':id' => array($id, PDO::PARAM_INT))); + $this->con->executeQuery( + $query, + array( + ':id' => array($id, PDO::PARAM_INT) + ) + ); } public function verifyAdministrator($administrator) diff --git a/Website/gateways/GatewayPlayer.php b/Website/gateways/GatewayPlayer.php index aa6615a..3ae17e7 100755 --- a/Website/gateways/GatewayPlayer.php +++ b/Website/gateways/GatewayPlayer.php @@ -17,6 +17,7 @@ class GatewayPlayer public function addPlayer($player) { + var_dump($player); $query = "insert into players(nickname,password) values (:nickname,:password);"; $this->con->executeQuery( $query, @@ -71,8 +72,27 @@ class GatewayPlayer ); } - public function deletePlayerByID(int $id) + public function updatePlayerPassword($id,$password) { + $query = "UPDATE players SET password = :password WHERE id = :id;"; + $this->con->executeQuery( + $query, + array( + ':id' => array($id, PDO::PARAM_INT), + ':password' => array(md5($password), PDO::PARAM_STR) + ) + ); + } + + public function deletePlayerByID($id) + { + $query = "DELETE FROM jouer WHERE idPlayer =:id;"; + $this->con->executeQuery( + $query, + array( + ':id' => array($id, PDO::PARAM_INT) + ) + ); $query = "DELETE FROM players WHERE id = :id;"; $this->con->executeQuery( $query, diff --git a/Website/models/ModelPlayer.php b/Website/models/ModelPlayer.php index 99a28d2..f103947 100644 --- a/Website/models/ModelPlayer.php +++ b/Website/models/ModelPlayer.php @@ -19,6 +19,7 @@ class ModelPlayer public function addPlayer($player) { + var_dump($player); $this->gwPlayer->addPlayer($player); } @@ -39,7 +40,10 @@ class ModelPlayer { $this->gwPlayer->updatePlayer($id, $player); } - + public function updatePlayerPassword($id, $player) + { + $this->gwPlayer->updatePlayerPassword($id, $player); + } public function deletePlayerByID($id) { $this->gwPlayer->deletePlayerByID($id); diff --git a/Website/templates/userPlayerModal.twig b/Website/templates/userPlayerModal.twig index f419f8e..7e2dec6 100644 --- a/Website/templates/userPlayerModal.twig +++ b/Website/templates/userPlayerModal.twig @@ -9,21 +9,17 @@ -