diff --git a/Controller/UserController.php b/Controller/UserController.php index f8b6be1c..f19b9844 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -463,27 +463,14 @@ class UserController require($rep . $vues['erreur']); } } - public function getPlayersEmail(){ - try { - global $rep, $vues, $error; - $model = new UserModel(); - $idPartie = $_SESSION['idPartie']; - $lesJoueurs = $model->getLesJoueurs($idPartie); - $lesJoueurs = json_encode($lesJoueurs); - echo ($lesJoueurs); - } - catch (Exception $e) { - $error = $e->getMessage(); - require($rep . $vues['erreur']); - } - } public function getPlayerScore(){ try { global $rep, $vues, $error; $model = new UserModel(); $idPartie = $_SESSION['idPartie']; - $joueur = $_POST['joueur']; - $score = $model->getPlayerScore($joueur, $idPartie); + $pseudo = $_POST['pseudo']; + $mailUtilisateur = $model->getMailFromPseudo($pseudo); + $score = $model->getPlayerScore($mailUtilisateur, $idPartie); $score = json_encode($score); echo $score; } diff --git a/Controller/UtilisateurGateway.php b/Controller/UtilisateurGateway.php index b9ee5bb6..6647a576 100644 --- a/Controller/UtilisateurGateway.php +++ b/Controller/UtilisateurGateway.php @@ -50,6 +50,20 @@ class UtilisateurGateway $results=$this->con->getResults(); return UtilisateurFactory::createUtilisateur($results); } + public function getMailByPseudo(string $pseudo) : string{ + global $error; + $query = "SELECT email FROM Utilisateur WHERE pseudo=:pseudo LIMIT 1"; + $this->con->executeQuery($query, array( + ':pseudo' => array($pseudo,SQLITE3_TEXT) + )); + $results=$this->con->getResults(); + $email = $results[0]['email']; + if ($results == null){ + $error = "Email non trouvé."; + throw new Exception("Email Incorrect"); + } + return $email; + } public function getMdpByEmail(string $email) : string{ global $error; diff --git a/Model/UserModel.php b/Model/UserModel.php index 7ee53a64..92c83f20 100644 --- a/Model/UserModel.php +++ b/Model/UserModel.php @@ -294,6 +294,9 @@ class UserModel } return $lesPseudos; } + public function getMailFromPseudo(string $pseudo) : string{ + return $this->utilisateur_gateway->getMailByPseudo($pseudo); + } public function getPlayerScore(string $mailUtilisateur,int $idPartie) : array{ global $playerNumberPerGame; $score = array(); diff --git a/View/src/JS/dashboard.js b/View/src/JS/dashboard.js index 4c6ca5ff..576175c5 100644 --- a/View/src/JS/dashboard.js +++ b/View/src/JS/dashboard.js @@ -1,12 +1,4 @@ function dashboard () { - var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayersEmail', true); - xhr.responseType = 'text'; - xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - var playersEmail = xhr.onload = function () { - console.log(xhr.responseText); - return JSON.parse(xhr.responseText); - }; xhr.send(null); var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayersPseudo', true); @@ -18,13 +10,13 @@ data = []; - if (playersEmail[0] != null) { + if (playersPseudo[0] != null) { v1 = {} v1.type="line"; v1.xValueFormatString=playersPseudo[0]; v1.dataPoints=[]; var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersEmail[0], true); + xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&pseudo='. playersPseudo[0], true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var score = xhr.onload = function () { @@ -37,13 +29,13 @@ data.push(v1); } - if (playersEmail[1] != null) { + if (playersPseudo[1] != null) { v2 = {} v2.type="line"; v2.xValueFormatString=playersPseudo[1]; v2.dataPoints=[]; var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersEmail[1], true); + xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersPseudo[1], true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var score = xhr.onload = function () { @@ -56,13 +48,13 @@ data.push(v2); } - if (playersEmail[2] != null) { + if (playersPseudo[2] != null) { v3 = {} v3.type="line"; v3.xValueFormatString=playersPseudo[2]; v3.dataPoints=[]; var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersEmail[2], true); + xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersPseudo[2], true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var score = xhr.onload = function () { @@ -75,13 +67,13 @@ data.push(v3); } - if (playersEmail[3] != null) { + if (playersPseudo[3] != null) { v4 = {} v4.type="line"; v4.xValueFormatString=playersPseudo[3]; v4.dataPoints=[]; var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersEmail[3], true); + xhr.open('POST', 'http://82.165.180.114/Scripted/index.php?action=getPlayerScore&joueur='. playersPseudo[3], true); xhr.responseType = 'text'; xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); var score = xhr.onload = function () {