diff --git a/src/Controleur/UserControler.php b/src/Controleur/UserControler.php index 8a4b5b3..19afef1 100644 --- a/src/Controleur/UserControler.php +++ b/src/Controleur/UserControler.php @@ -1,7 +1,11 @@ = $total_questions) { - session_destroy(); + $_SESSION['no_question'] = 0; $this->endQuiz($id_quiz, $score); } else header("Location: ".$racine."/quiz/$id_quiz"); ///~kekentin/WF/WF-Website @@ -180,7 +185,7 @@ class UserControler { */ public function showQuestion(int $id, int $num) : void { - global $vues; + global $vues,$twig; $q = $this->GetQuestion($id); $question = $q[$num] ?? $q[0]; $idquestion = $question->getIdQuestion(); @@ -232,9 +237,11 @@ class UserControler { $_SESSION['user'] = $newPseudo; } } + else if($newEmail){ $user = $this-> uMod->setEmail($_SESSION['user'], $newEmail); } + else if($newMdpFirst && $newMdpSecond){ if($newMdpFirst == $newMdpSecond){ @@ -242,12 +249,111 @@ class UserControler { $option = ['cost' => 12]; $newPassWd = password_hash($newMdpFirst, PASSWORD_BCRYPT, $option); $user = $this-> uMod->setPassWd($_SESSION['user'], $newPassWd); - } + } } + else if($newImage){ $user = $this->uMod->setImage($_SESSION['user']); } } - header("Location: /~lebeaulato/WF-Website/profil"); + header("Location: ". $racine."/profil"); + + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function submit() : void + { + global $twig; + echo $twig -> render("submitQuote.html.twig"); + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function toSubmit() : ?array + { + global $co; + if ($_POST) + { + $content = $_POST['content'] ?? null; + $character = $_POST['character'] ?? null; + $source = $_POST['source'] ?? null; + //$img = $_POST['img'] ?? null; + + $errors = [null, null]; + + $gw = new CharacterGateway($co); + $mdl = new CharacterModel($gw); + + $character = $mdl -> getCharacterByName($character); + + $gw = new SourceGateway($co); + $mdl = new SourceModel($gw); + + $source = $mdl -> getSourceByTitle($source); + + if (!$character) + $errors[0] = "Personnage inexistant"; + if (!$source) + $errors[1] = "Source inexistante"; + if ($errors[0] || $errors[1]) + { + global $twig; + echo $twig->render("submitQuote.html.twig", ['errors' => $errors]); + exit(); + } + + $gw = new QuoteGateway($co); + $mdl = new QuoteModel($gw); + + $mdl -> insert4User($content, '/imgPath', 'fr', $this -> getIdOfUser(), $source->getIdSource(), $character->getIdCharacter()); + + return [$content, $_POST['character'], $_POST['source']]; + } + return null; + } + + /** + * @throws SyntaxError + * @throws RuntimeError + * @throws LoaderError + */ + public function validsubmit() : void + { + $recap = $this -> toSubmit(); + if ($recap) + { + $this -> recapSubmitQuote($recap); + } + } + + /** + * @throws RuntimeError + * @throws SyntaxError + * @throws LoaderError + */ + public function recapSubmitQuote(?array $recap) : void + { + global $twig; + echo $twig -> render("recapSubmitQuote.html.twig", ['content' => $recap[0], 'character' => $recap[1], 'source' => $recap[2]]); + } + + public function getIdOfUser() : ?int + { + if (isset($_SESSION['user'])) + { + global $co; + $gw = new UserGateway($co); + $mdl = new UserModel($gw); + + return $mdl -> getUsername($_SESSION['user']) -> getId(); + } + return null; } } diff --git a/vue/templates/profil.html.twig b/vue/templates/profil.html.twig index 645a20d..d9ac021 100644 --- a/vue/templates/profil.html.twig +++ b/vue/templates/profil.html.twig @@ -3,9 +3,8 @@

▶ Profil ◀

- - - + +

{{ srcUsername }}