diff --git a/WEB/Controller/PartieGateway.php b/WEB/Controller/PartieGateway.php index a71716f3..93f0d721 100644 --- a/WEB/Controller/PartieGateway.php +++ b/WEB/Controller/PartieGateway.php @@ -350,6 +350,18 @@ class PartieGateway $this->con->executeQuery($query,array( 'partie' => array($idPartie,SQLITE3_INTEGER))); } + public function checkUserIsInPartie(string $mailUtilisateur) : bool { + $query = "SELECT * FROM Participer WHERE utilisateur = :mailUtilisateur"; + $this->con->executeQuery($query, array( + "mailUtilisateur" => array($mailUtilisateur, SQLITE3_TEXT) + ) + ); + $results = $this->con->getResults(); + if(count($results) == 0 || $results == null){ + return false; + } + return true; + } public function showAll(): void { $query = "SELECT * FROM Partie"; diff --git a/WEB/Controller/UserController.php b/WEB/Controller/UserController.php index 4a5997e2..112a7d99 100644 --- a/WEB/Controller/UserController.php +++ b/WEB/Controller/UserController.php @@ -239,6 +239,9 @@ class UserController global $rep, $vues, $error; $model = new UserModel(); $utilisateur = $_SESSION['utilisateur']; + if ($model->checkUserIsInPartie($utilisateur->getEmail())){ + throw new Exception("Vous êtes déjà dans une partie"); + } $idPartie = $model->addToQueue($utilisateur->getEmail()); $_SESSION['idPartie'] = $idPartie; require($rep . $vues['queue']); @@ -279,7 +282,6 @@ class UserController public function logout() { session_destroy(); - // $_SESSION['role'] = 'visitor'; header('Location: index.php'); } diff --git a/WEB/Model/UserModel.php b/WEB/Model/UserModel.php index 51346589..f2ba2e6e 100644 --- a/WEB/Model/UserModel.php +++ b/WEB/Model/UserModel.php @@ -230,4 +230,8 @@ class UserModel public function endGame(int $idPartie) { $this->partie_gateway->endGame($idPartie); } + + public function checkUserIsInPartie(string $mailUtilisateur) : bool{ + return $this->partie_gateway->checkUserIsInPartie($mailUtilisateur); + } } \ No newline at end of file diff --git a/WEB/View/src/JS/Queu.js b/WEB/View/src/JS/Queu.js deleted file mode 100644 index ffc22587..00000000 --- a/WEB/View/src/JS/Queu.js +++ /dev/null @@ -1,21 +0,0 @@ -function displayWaiting(){ - document.getElementById("waiting").innerHTML = "Waiting for Coders..."; - document.getElementsByClassName("btn").style.display = "none" -} - -function checkIsReady() { - var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/WEB/index.php?action=waiting', true); - xhr.responseType = 'text'; - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - xhr.onload = function () { - if (xhr.responseText == "1") { - window.location.href = 'http://82.165.180.114/Scripted/WEB/index.php?action=goToGame&idPartie=" . $idPartie . "&index=1"' - } - }; - xhr.send(null); -} -function waiting(){ - displayWaiting(); - var countdownTimer = setInterval('checkIsReady()', 1000); -} \ No newline at end of file diff --git a/WEB/View/src/pages/Multijoueur/GameEnd.php b/WEB/View/src/pages/Multijoueur/GameEnd.php index 84b3955a..16d4a194 100644 --- a/WEB/View/src/pages/Multijoueur/GameEnd.php +++ b/WEB/View/src/pages/Multijoueur/GameEnd.php @@ -14,7 +14,7 @@
- Retour + RetourBien joué à tous la partie est finis, voici le classement :