From 51d2ee5728696798e0eb2f640ffe95eccf8a1aac Mon Sep 17 00:00:00 2001 From: tomivt Date: Sat, 9 Nov 2024 13:33:52 +0100 Subject: [PATCH 1/5] Add Session --- .idea/material_theme_project_new.xml | 4 ++- .idea/workspace.xml | 45 ++++++++++------------- index.php | 5 ++- src/Controleur/QuizController.php | 53 +++++++++++++--------------- src/Model/QuizModel.php | 4 +-- vue/templates/quiz.html.twig | 21 +++-------- 6 files changed, 54 insertions(+), 78 deletions(-) diff --git a/.idea/material_theme_project_new.xml b/.idea/material_theme_project_new.xml index 0d9afcc..b631df8 100644 --- a/.idea/material_theme_project_new.xml +++ b/.idea/material_theme_project_new.xml @@ -3,7 +3,9 @@ diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 882bd96..d977ec5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,19 +5,12 @@ - + + - - - - - - - - - - + + - { + "keyToString": { + "RunOnceActivity.ShowReadmeOnStart": "true", + "git-widget-placeholder": "master", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "vue.rearranger.settings.migration": "true" }, - "keyToStringList": { - "DatabaseDriversLRU": [ - "postgresql" + "keyToStringList": { + "DatabaseDriversLRU": [ + "postgresql" ] } -}]]> +} @@ -121,7 +114,7 @@ diff --git a/index.php b/index.php index bebf483..400e2ef 100644 --- a/index.php +++ b/index.php @@ -19,11 +19,10 @@ $twig = new \Twig\Environment($loader, [ 'cache' => 'cache', ]); +$num = 0; + $cont = new Controleur\FrontControler($co); -session_unset(); -session_destroy(); -$_SESSION = array(); ?> \ No newline at end of file diff --git a/src/Controleur/QuizController.php b/src/Controleur/QuizController.php index 3b81996..65fe758 100644 --- a/src/Controleur/QuizController.php +++ b/src/Controleur/QuizController.php @@ -1,5 +1,6 @@ co = $co; $this -> gw = new QuestionGateway($this->co); $this -> mdl = new QuestionModel($this->gw); - - $loader = new FilesystemLoader('vue/templates'); + global $num; + global $loader; $action = $_REQUEST['action'] ?? null; @@ -46,13 +48,12 @@ class QuizController switch ($action) { case 'canswer': - if ($this->CorrectAnswer()) echo "Bonne réponse"; else echo "Mauvaise réponse"; - $this->no_question ++; - echo $this->no_question; - $this->showQuestion($id, $this->no_question); + $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1; + + header("Location: http://localhost:8000/quiz/$id"); break; default: switch($id) @@ -61,7 +62,7 @@ class QuizController // page erreur break; default: - $this->showQuestion($id, $this->no_question); + $this->showQuestion($id, $_SESSION['no_question'] ?? 0); break; } } @@ -103,42 +104,36 @@ class QuizController return $mdl->getAllQuestionByQuiz($id, $this->co); } + public function RunQuiz(int $idQuiz) + { + + } + /** * @throws RuntimeError * @throws SyntaxError * @throws LoaderError */ - public function showQuestion(int $id, int $no) : void + public function showQuestion(int $id, int $num) : void { global $twig; + echo $num; $q = $this->GetQuestion($id); - $question = $q[$no]; - + $question = $q[$num]; $idquestion = $question->getIdQuestion(); echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); - } - - public function getNumberOfQuestion() : int - { - $gw = new QuizGateway($this->co); - $mdl = new QuizModel($gw); - return 0; + //else + //page resultat } -} - -/* -getUrl() ?>> getTitle() ?> + $gw = new QuizGateway($this->co); + $mdl = new QuizModel($gw); + return $mdl->getQuiz($id)->getNbQuestions(); } -?> - - -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/src/Model/QuizModel.php b/src/Model/QuizModel.php index 728d516..155a512 100644 --- a/src/Model/QuizModel.php +++ b/src/Model/QuizModel.php @@ -24,8 +24,8 @@ class QuizModel { $q = $this -> gateway -> findQuizById($id_quiz); if ($q) { return new quizEntity( - $q['id_quiz'], - $q['nb_questions'], + $q[0]['id_quiz'], + $q[0]['nb_quest'] ); } return null; diff --git a/vue/templates/quiz.html.twig b/vue/templates/quiz.html.twig index f78dd54..b53270d 100644 --- a/vue/templates/quiz.html.twig +++ b/vue/templates/quiz.html.twig @@ -9,7 +9,7 @@ -
- - -
- user -
-
- + {{ include "bandeau.html.twig" }}

▶ Quiz ◀

{{ question.question }}

- 300 seconds left .. + 10 seconds left ..
@@ -59,7 +46,7 @@ {{ question.answerd }}
- +
From 10ac911cc70816b81c210242766726a54ff7fef3 Mon Sep 17 00:00:00 2001 From: tomivt Date: Sat, 9 Nov 2024 14:55:04 +0100 Subject: [PATCH 2/5] Add Score + Start endQuiz View --- .idea/workspace.xml | 35 ++++--- cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php | 95 +++++++++++++++++++ src/Controleur/QuizController.php | 63 ++++++++---- vue/templates/endQuiz.html.twig | 19 ++++ 4 files changed, 173 insertions(+), 39 deletions(-) create mode 100644 cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php create mode 100644 vue/templates/endQuiz.html.twig diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d977ec5..449c40f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,12 +5,8 @@ - - - - + + + - { - "keyToString": { - "RunOnceActivity.ShowReadmeOnStart": "true", - "git-widget-placeholder": "master", - "node.js.detected.package.eslint": "true", - "node.js.detected.package.tslint": "true", - "node.js.selected.package.eslint": "(autodetect)", - "node.js.selected.package.tslint": "(autodetect)", - "nodejs_package_manager_path": "npm", - "vue.rearranger.settings.migration": "true" + +}]]> diff --git a/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php new file mode 100644 index 0000000..d4d5fd6 --- /dev/null +++ b/cache/1c/1cd62e96738e2a4531dcc1f47d504b1a.php @@ -0,0 +1,95 @@ + + */ + private array $macros = []; + + public function __construct(Environment $env) + { + parent::__construct($env); + + $this->source = $this->getSourceContext(); + + $this->parent = false; + + $this->blocks = [ + ]; + } + + protected function doDisplay(array $context, array $blocks = []): iterable + { + $macros = $this->macros; + // line 1 + yield " + + + + + Wiki Fantasy : Quiz + + + + + + + +

"; + // line 14 + yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(($context["score"] ?? null), "html", null, true); + yield "

+ + + + +"; + yield from []; + } + + /** + * @codeCoverageIgnore + */ + public function getTemplateName(): string + { + return "endQuiz.html.twig"; + } + + /** + * @codeCoverageIgnore + */ + public function isTraitable(): bool + { + return false; + } + + /** + * @codeCoverageIgnore + */ + public function getDebugInfo(): array + { + return array ( 57 => 14, 42 => 1,); + } + + public function getSourceContext(): Source + { + return new Source("", "endQuiz.html.twig", "/Users/kiem/Documents/WikiFantasy/WF-Website/vue/templates/endQuiz.html.twig"); + } +} diff --git a/src/Controleur/QuizController.php b/src/Controleur/QuizController.php index 65fe758..e0dcee7 100644 --- a/src/Controleur/QuizController.php +++ b/src/Controleur/QuizController.php @@ -1,6 +1,4 @@ co = $co; - $this -> gw = new QuestionGateway($this->co); - $this -> mdl = new QuestionModel($this->gw); + $this -> gw = new QuestionGateway($this -> co); + $this -> mdl = new QuestionModel($this -> gw); global $num; global $loader; $action = $_REQUEST['action'] ?? null; $id = (int) explode('/', $_SERVER['REQUEST_URI'])[2] ?? null; + $nb_questions = $this->getNumberOfQuestion($id); switch ($action) { case 'canswer': if ($this->CorrectAnswer()) - echo "Bonne réponse"; - else echo "Mauvaise réponse"; - $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1; - - header("Location: http://localhost:8000/quiz/$id"); + $_SESSION['score'] = isset($_SESSION['score']) ? ($_SESSION['score'] + 1) : 1; + $this->continueQuiz($id, $nb_questions); break; default: switch($id) @@ -62,6 +56,7 @@ class QuizController // page erreur break; default: + $_SESSION['score'] = $_SESSION['score'] ?? 0; $this->showQuestion($id, $_SESSION['no_question'] ?? 0); break; } @@ -69,6 +64,40 @@ class QuizController } + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function continueQuiz(int $id_quiz, int $total_questions) : void + { + $score = $_SESSION['score']; + $_SESSION['no_question'] = isset($_SESSION['no_question']) ? ($_SESSION['no_question'] + 1) : 1; + if ($_SESSION['no_question'] >= $total_questions) { + session_destroy(); + $this->endQuiz($id_quiz, $score); + } + else header("Location: http://localhost:8000/quiz/$id_quiz"); + + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function endQuiz(int $id_quiz, int $score) : void + { + global $twig; + + $gw = new QuizGateway($this->co); + $mdl = new QuizModel($gw); + + if ($mdl->getQuiz($id_quiz + 1)) + echo $twig->render('endQuiz.html.twig', ['score' => $score, 'nextquiz' => $id_quiz + 1]); + echo $twig->render('endQuiz.html.twig', ['score' => $score]); + } + public function CorrectAnswer() : bool { $answera = $_POST['answera'] ?? null; @@ -104,11 +133,6 @@ class QuizController return $mdl->getAllQuestionByQuiz($id, $this->co); } - public function RunQuiz(int $idQuiz) - { - - } - /** * @throws RuntimeError * @throws SyntaxError @@ -118,14 +142,11 @@ class QuizController { global $twig; echo $num; + echo " : ", $_SESSION['score']; $q = $this->GetQuestion($id); - $question = $q[$num]; + $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); echo $twig->render('quiz.html.twig', ['question' => $question,'id'=>$idquestion]); - - //else - //page resultat - } diff --git a/vue/templates/endQuiz.html.twig b/vue/templates/endQuiz.html.twig new file mode 100644 index 0000000..b34f4ea --- /dev/null +++ b/vue/templates/endQuiz.html.twig @@ -0,0 +1,19 @@ + + + + + + Wiki Fantasy : Quiz + + + + + + + +

{{ score }}

+

{{ nextquiz }}

+ +zeze + + From 5f742119aab65eeec84bfecbedd76ae7b9f96769 Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Tue, 12 Nov 2024 08:43:59 +0100 Subject: [PATCH 3/5] modif --- config/config.php | 2 +- index.php | 2 +- vue/login.php | 2 +- vue/quote.php | 2 +- vue/templates/login.html | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.php b/config/config.php index 60abcb1..bfa17ed 100644 --- a/config/config.php +++ b/config/config.php @@ -11,7 +11,7 @@ $rep = __DIR__ . '/../'; $base = 'dbkemondejar'; $login = 'kemondejar'; -$mdp = ''; +$mdp = 'Ctvl-21122005'; //Vues diff --git a/index.php b/index.php index 5b3e0d1..d76fc9d 100644 --- a/index.php +++ b/index.php @@ -19,7 +19,7 @@ $twig = new \Twig\Environment($loader, [ 'cache' => false, ]); -$twig->addGlobal('racine','/~kekentin/WF/WF-Website'); +$twig->addGlobal('racine','/~kemondejar/WF-Website'); $cont = new Controleur\FrontControler($co); diff --git a/vue/login.php b/vue/login.php index e6fea79..8abfc20 100644 --- a/vue/login.php +++ b/vue/login.php @@ -4,7 +4,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Login", - 'style' => "public/styles/styleLogin.css", + 'style' => "public/styles/styleLogin.css", )); echo $twig->render('bandeau.html.twig'); diff --git a/vue/quote.php b/vue/quote.php index 8332bf2..0b7f5e2 100644 --- a/vue/quote.php +++ b/vue/quote.php @@ -4,7 +4,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Quote", - 'style' => "public/styles/styleQuote.css", + 'style' => "../public/styles/styleQuote.css", )); echo $twig->render('bandeau.html.twig'); echo $twig->render('quote.html', array( diff --git a/vue/templates/login.html b/vue/templates/login.html index e4cd68d..3005264 100644 --- a/vue/templates/login.html +++ b/vue/templates/login.html @@ -6,7 +6,7 @@ quizz
user @@ -24,7 +24,7 @@

Vous n'avez pas de compte?

- S'incrire + S'incrire
From 0bef52622b586adaa7fa59d2a47d8dcea8008f2c Mon Sep 17 00:00:00 2001 From: "kevin.modejar" Date: Tue, 12 Nov 2024 09:24:13 +0100 Subject: [PATCH 4/5] =?UTF-8?q?modif=20certain=20probl=C3=A8me=20quote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controleur/FrontControler.php | 2 +- src/Controleur/VisitorControler.php | 3 +-- vue/accueil.php | 1 + vue/login.php | 1 + vue/quote.php | 2 +- vue/signin.php | 1 + vue/templates/head.html.twig | 6 +++++- vue/templates/quote.html | 2 +- 8 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Controleur/FrontControler.php b/src/Controleur/FrontControler.php index f9d30b4..65421c0 100644 --- a/src/Controleur/FrontControler.php +++ b/src/Controleur/FrontControler.php @@ -37,7 +37,7 @@ Class FrontControler{ '' => '[^/\.]++' */ - $router->map('GET|POST', '/quote/[i:idQuote]?', 'VisitorControler','quote'); + $router->map('GET|POST', '/quote/[i:idQuote]', 'VisitorControler','quote'); $router->map('GET|POST', '/login', 'VisitorControler','login'); $router->map('GET|POST', '/signin', 'VisitorControler','signin'); diff --git a/src/Controleur/VisitorControler.php b/src/Controleur/VisitorControler.php index bbf20a5..fd855c7 100644 --- a/src/Controleur/VisitorControler.php +++ b/src/Controleur/VisitorControler.php @@ -20,9 +20,8 @@ Class VisitorControler{ public function quote(array $arg){ global $vues; - $id=$arg['idQuote'] ?? 1; + $id=$arg['idQuote']; $q = $this->qMod->searchId($id); - //echo "{$id}"; require_once $vues['quote']; } diff --git a/vue/accueil.php b/vue/accueil.php index 5c6d764..e958d5e 100644 --- a/vue/accueil.php +++ b/vue/accueil.php @@ -4,6 +4,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Accueil", 'style' => "public/styles/styleAccueil.css", + 'scripts' => array("public/script/theme-toggle.js") )); echo $twig->render('bandeau.html.twig'); diff --git a/vue/login.php b/vue/login.php index 8abfc20..39ec7a4 100644 --- a/vue/login.php +++ b/vue/login.php @@ -5,6 +5,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Login", 'style' => "public/styles/styleLogin.css", + 'scripts' => array("public/script/theme-toggle.js") )); echo $twig->render('bandeau.html.twig'); diff --git a/vue/quote.php b/vue/quote.php index 0b7f5e2..9466ceb 100644 --- a/vue/quote.php +++ b/vue/quote.php @@ -5,6 +5,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Quote", 'style' => "../public/styles/styleQuote.css", + 'scripts' => array("../public/script/theme-toggle.js") )); echo $twig->render('bandeau.html.twig'); echo $twig->render('quote.html', array( @@ -14,7 +15,6 @@ 'sourceName' => $q->getTitleSrc(), 'dateSortie' => $q->getDateSrc(), 'nbLike' => $q->getLike(), - 'timeCode' =>"1h45", )); ?> \ No newline at end of file diff --git a/vue/signin.php b/vue/signin.php index 4cef884..efb8cd3 100644 --- a/vue/signin.php +++ b/vue/signin.php @@ -5,6 +5,7 @@ echo $twig->render('head.html.twig', array( 'title' => "Sign in", 'style' => "public/styles/styleSignin.css", + 'scripts' => array("public/script/theme-toggle.js") )); echo $twig->render('bandeau.html.twig'); diff --git a/vue/templates/head.html.twig b/vue/templates/head.html.twig index 31c1ef9..8d9e7ce 100644 --- a/vue/templates/head.html.twig +++ b/vue/templates/head.html.twig @@ -6,6 +6,10 @@ {{ title }} - + {% if scripts|length > 0 %} + {% for script in scripts %} + + {% endfor %} + {% endif %} \ No newline at end of file diff --git a/vue/templates/quote.html b/vue/templates/quote.html index ddf2581..7395b09 100644 --- a/vue/templates/quote.html +++ b/vue/templates/quote.html @@ -5,7 +5,7 @@

“{{quoteContent}}”

    -
  • - {{sourceName}} ({{timeCode}})
  • +
  • - {{sourceName}}
  • - {{nameCarac}}
  • - {{dateSortie}}
From cecf7461496fb94ceccb22365e49ae643cb9f768 Mon Sep 17 00:00:00 2001 From: Leni BEAULATON Date: Tue, 12 Nov 2024 09:56:57 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'src/Gateway/us?= =?UTF-8?q?erGateway.php'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Gateway/userGateway.php | 119 ++++++++++++++++++++++++++++-------- 1 file changed, 92 insertions(+), 27 deletions(-) diff --git a/src/Gateway/userGateway.php b/src/Gateway/userGateway.php index 4760260..1ba5805 100644 --- a/src/Gateway/userGateway.php +++ b/src/Gateway/userGateway.php @@ -11,31 +11,26 @@ Class UserGateway{ public function insert(string $username,string $email,string $passwd):string{ - // récupération id - $query='SELECT id_user FROM Users WHERE id_user >= ALL (SELECT id_user FROM Users);'; - $this->con->executeQuery($query); - $result=$this->con->getResults(); - foreach($result as $row){ - $id=$row['id_user'] + 1; - } + //crypte passeword + $passwordEncrypted = crypt($passwd); // insertion user - $query='INSERT INTO Users VALUES (:id,:username,:email,:passwd,CURRENT_DATE,false);'; - $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR),':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwd,PDO::PARAM_STR))); + $query='INSERT INTO Users VALUES (:username,:email,:passwd,CURRENT_DATE,false);'; + $this->con->executeQuery($query,array(':username' => array($u->username,PDO::PARAM_STR),':email' => array($u->email,PDO::PARAM_STR),':passwd' => array($u->passwordEncrypted,PDO::PARAM_STR))); return $id; } public function delete(string $id) : bool{ - // supretion user + // suppression user $query='DELETE FROM Users WHERE id_user = :id;'; - return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); + return $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); } public function getFavorite(string $id):array{ //obtention favoris d'un user $query='SELECT * FROM Quote WHERE id_quote IN (SELECT id_quote IN Favorite f JOIN User u ON u.id_user = f.user WHERE id_user = :id);'; - $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_STR))); + $this->con->executeQuery($query,array(':id' => array($id,PDO::PARAM_INT))); $result=$this->con->getResults(); return $result; } @@ -44,32 +39,101 @@ Class UserGateway{ //obtenir les information d'un user public function findDataUser(int $id):array{ $query = 'SELECT * FROM Users WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR))); + $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT))); $result = $con->getResults(); return $result; } + public function createQuote(int $id, string $content, string $langue, string $caracter, string $source):array{ + + //recupère id du personnage + $queryCaracter = "SELECT id_caracter FROM Caracter WHERE caracter =:caracter"; + $con->executeQuery($queryCaracter, array( + ':caracter'=>array($caracter, PDO::PARAM_STR) + )); + $resultCaracter = $con->getResult(); + + if($resultCaracter == NULL){ + //ajout creationCaracter + } + + //recupère id de la source + $querySource = "SELECT id_source FROM Source WHERE title =:source"; + $con->executeQuery($querySource, array( + ':source'=>array($source, PDO::PARAM_STR) + )); + $resultSource = $con->getResult(); + + if($resultSource == NULL){ + //ajout creationSource + } + $queryInsert = "INSERT INTO Quote (content, langue, id_caracter, id_source, id_user_verif) VALUES (:content, :langue, :caracter, :source, :idverif)"; + $con->executeQuery($queryInsert, array( + ':content'=>array($content, PDO::PARAM_STR), + ':langue'=>array($langue, PDO::PARAM_STR), + ':caracter'=>array($resultCaracter, PDO::PARAM_STR), + ':source'=>array($resultSource, PDO::PARAM_STR), + ':idverif'=>array($id, PDO::PARAM_INT) + )); + } + + + + public function createCaracter(string $caracter, string $img):array{ + //creation du personnage + $queryCaracter = "INSERT INTO Caracter(caracter, img_path) VALUES (:caracter, :img)"; + $con->executeQuery($queryCaracter, array( + ':caracter'=>array($caracter, PDO::PARAM_STR), + 'img'=>array($img, PDO::PARAM_STR) + )); + + //récuperation de id caracter + $queryCaracter = "SELECT id_caracter FROM Caracter WHERE caracter =:caracter"; + $con->executeQuery($queryCaracter, array( + ':caracter'=>array($caracter, PDO::PARAM_STR) + )); + $resultCaracter = $con->getResult(); + } + + + + public function createSource(string $title, string $dateS):array{ + //creation du personnage + $querySource = "INSERT INTO Source(title, dateS) VALUES (:title, :dateS)"; + $con->executeQuery($querySource, array( + ':title'=>array($title, PDO::PARAM_STR), + 'dateS'=>array($dateS, PDO::PARAM_STR) + )); + + //recupère id de la source + $querySource = "SELECT id_source FROM Source WHERE title =:source"; + $con->executeQuery($querySource, array( + ':source'=>array($source, PDO::PARAM_STR) + )); + $querySource = $con->getResult(); + } + // ===================== UPDATE FUNCTION ===================== public function updateUsername(int $id, string $newUsername):array{ //Update le nom du user passé en paramètre $queryUpdate = 'UPDATE Users SET username=:newUsername WHERE id_user=:idUser'; - $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newUsername'=> array($newUsername, PDO::PARAM_STR))); + $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_INT), ':newUsername'=> array($newUsername, PDO::PARAM_STR))); //Renvoie le nouveau nom du user $queryReponse = 'SELECT username FROM Users WHERE id_user=:idUser'; - $con->executeQuery($queryReponse, array($id=>array($newUsername, PDO::PARAM_STR))); + $con->executeQuery($queryReponse, array($id=>array($id, PDO::PARAM_INT))); return $result; } public function updateEmail(int $id, string $newEmail):array{ //Update le email du user passé en paramètre $queryUpdate = 'UPDATE Users SET email=:newEmail WHERE id_user=:idUser'; - $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_STR), ':newEmail'=> array($newEmail, PDO::PARAM_STR))); + $con->executeQuery($queryUpdate, array(':idUser'=>array($id, PDO::PARAM_INT), ':newEmail'=> array($newEmail, PDO::PARAM_STR))); //Renvoie le nouveau email du user $queryReponse = 'SELECT email FROM Users WHERE id_user=:idUser'; - $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); + $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_INT))); $result = $con->getResults(); return $result; } @@ -77,29 +141,30 @@ Class UserGateway{ public function updateImg(int $id, int $newImg):array{ //Update l'image du user passé en paramètre $query = 'UPDATE Users SET img=:newImg WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newImg'=> array($newImg, PDO::PARAM_STR))); + $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT), ':newImg'=> array($newImg, PDO::PARAM_STR))); //Renvoie la nouvelle image du user $queryReponse = 'SELECT img FROM Users WHERE id_user=:idUser'; - $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); + $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_INT))); $result = $con->getResults(); return $result; } public function updatePasswd(int $id, string $newPassWd):array{ - //Update le passwd du user passé en paramètre - $query = 'UPDATE Users SET pssword=:newPassWd WHERE id_user=:idUser'; - $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_STR), ':newPassWd'=> array($newPassWd, PDO::PARAM_STR))); - //Renvoie le nouveau passwd du user - $queryReponse = 'SELECT pssword FROM Users WHERE id_user=:idUser'; - $con->executeQuery($queryReponse, array(':idUser'=>array($id, PDO::PARAM_STR))); - $result = $con->getResults(); - return $result; + //crypte le mot de passe + $passwordEncrypted = crypt($newPassWd); + + //Update le passwd du user passé en paramètre + $query = 'UPDATE Users SET password=:newPassWd WHERE id_user=:idUser'; + $con->executeQuery($query, array(':idUser'=>array($id, PDO::PARAM_INT), ':newPassWd'=> array($passwordEncrypted, PDO::PARAM_STR))); } } + + + $uG = new UserGateway(new Connection("pgsql:host=londres;dbname=dblebeaulato","lebeaulato","")); ?>