From 5cdc0e6ddcd5d632cf226051dc906191f26377ad Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Mon, 20 Nov 2023 14:51:34 +0100 Subject: [PATCH 1/7] ajouter getsexes --- project/src/model/gateways/SexeGateway.php | 6 ++++++ project/src/model/mdl/MdlSexe.php | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/project/src/model/gateways/SexeGateway.php b/project/src/model/gateways/SexeGateway.php index 3a4e608..f2672cf 100644 --- a/project/src/model/gateways/SexeGateway.php +++ b/project/src/model/gateways/SexeGateway.php @@ -16,4 +16,10 @@ class SexeGateway [':id' => [$id, $this->con::PARAM_INT]]); return $this->con->getOneResult(); } + + public function getSexes(): array + { + $this->con->executeQuery("SELECT id, libelle FROM Sexe;"); + return $this->con->getResults(); + } } \ No newline at end of file diff --git a/project/src/model/mdl/MdlSexe.php b/project/src/model/mdl/MdlSexe.php index bc9cf40..0bb7362 100644 --- a/project/src/model/mdl/MdlSexe.php +++ b/project/src/model/mdl/MdlSexe.php @@ -14,4 +14,12 @@ class MdlSexe extends MdlBase{ $row = $this->gw->getFromId($id); return new Sexe($row['id'], $row['libelle']); } + public function getSexes(): array { + $ret=array(); + $row = $this->gw->getSexes(); + for($i=0; $i< count($row); $i++){ + array_push($ret, new Sexe($row[$i]['id'], $row[$i]['libelle'])); + } + return $ret; + } } \ No newline at end of file From 5078d4a91a5bfbdfd211c1b8979c3188dc9de96f Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Mon, 20 Nov 2023 18:58:39 +0100 Subject: [PATCH 2/7] ajouter isAdmin et isLogged aux sessions --- project/src/controller/FrontController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index d5ef12a..241dae0 100644 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -77,14 +77,16 @@ class FrontController $ug = new MdlUser(); if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { $_SESSION['pseudo'] = $_REQUEST['login']; + $_SESSION['isLogged'] = true; header("Location: ."); } else { - //todo : verifier si utilisateur existe dans User ou Admin au lieu de login les 2 a la fois //voir si c'est un admin $ug = new MdlAdmin(); if($ug->login($_REQUEST['login'], $_REQUEST['password'])) { - $_SESSION['pseudo'] = $_REQUEST['login']; - header("Location: ."); + $_SESSION['pseudo'] = $_REQUEST['login']; + $_SESSION['isAdmin'] = true; + $_SESSION['isLogged'] = true; + header("Location: ."); } else { $dVueErreur[] = "Connexion échouée"; throw new LoginException("Connexion err"); From 40af2afbd1c52d41299016514531c2a625f031cc Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Mon, 20 Nov 2023 18:59:29 +0100 Subject: [PATCH 3/7] modifier mdl et gateway --- .../src/model/gateways/ScientifiqueGateway.php | 18 +++++++++++++++++- project/src/model/gateways/SexeGateway.php | 2 +- .../src/model/gateways/ThematiqueGateway.php | 5 +++++ project/src/model/mdl/MdlScientifique.php | 3 +++ project/src/model/mdl/MdlSexe.php | 4 ++-- project/src/model/mdl/MdlThematique.php | 9 +++++++++ 6 files changed, 37 insertions(+), 4 deletions(-) diff --git a/project/src/model/gateways/ScientifiqueGateway.php b/project/src/model/gateways/ScientifiqueGateway.php index a863ea2..f3ead18 100644 --- a/project/src/model/gateways/ScientifiqueGateway.php +++ b/project/src/model/gateways/ScientifiqueGateway.php @@ -10,9 +10,25 @@ class ScientifiqueGateway $this->con = $con; } - public function getRandom(): array|bool{ + public function getRandom() { $this->con->executeQuery( "SELECT id, nom, prenom, photo, dateNaissance, descriptif, ratiotrouvee, idthematique, iddifficulte, idsexe FROM Scientifique ORDER BY RANDOM() LIMIT 1;"); return $this->con->getOneResult(); } + + public function addScientifique(Scientifique $sci): bool{ + return $this->con->executeQuery( + "INSERT INTO Scientifique(nom, prenom, photo, dateNaissance, descriptif, ratioTrouvee, idThematique, idDifficulte, idSexe) VALUES (:nom, :prenom, :photo, :dateNaissance, :descriptif, :ratioTrouvee, :idThematique, :idDifficulte, :idSexe);" + ,[ + ":nom"=>[$sci->getNom(),$this->con::PARAM_STR], + ":prenom"=>[$sci->getPrenom(),$this->con::PARAM_STR], + ":photo"=>[$sci->getPhoto(),$this->con::PARAM_STR], + ":dateNaissance"=>[date("Y-m-d H:i:s", $sci->getDateNaiss()->getTimestamp()),$this->con::PARAM_STR], + ":descriptif"=>[$sci->getDescriptif(),$this->con::PARAM_STR], + ":ratioTrouvee"=>[$sci->getRatioTrouvee(),$this->con::PARAM_STR], + ":idThematique"=>[$sci->getThematique()->getId(),$this->con::PARAM_STR], + ":idDifficulte"=>[$sci->getDifficulte()->getId(),$this->con::PARAM_STR], + ":idSexe"=>[$sci->getSexe()->getId(),$this->con::PARAM_STR] + ]); + } } \ No newline at end of file diff --git a/project/src/model/gateways/SexeGateway.php b/project/src/model/gateways/SexeGateway.php index f2672cf..833920b 100644 --- a/project/src/model/gateways/SexeGateway.php +++ b/project/src/model/gateways/SexeGateway.php @@ -17,7 +17,7 @@ class SexeGateway return $this->con->getOneResult(); } - public function getSexes(): array + public function getAll(): array { $this->con->executeQuery("SELECT id, libelle FROM Sexe;"); return $this->con->getResults(); diff --git a/project/src/model/gateways/ThematiqueGateway.php b/project/src/model/gateways/ThematiqueGateway.php index deb64cf..59a1166 100644 --- a/project/src/model/gateways/ThematiqueGateway.php +++ b/project/src/model/gateways/ThematiqueGateway.php @@ -16,4 +16,9 @@ class ThematiqueGateway [':id' => [$id, $this->con::PARAM_INT]]); return $this->con->getOneResult(); } + public function getAll(): array + { + $this->con->executeQuery("SELECT id, libelle FROM Thematique;"); + return $this->con->getResults(); + } } \ No newline at end of file diff --git a/project/src/model/mdl/MdlScientifique.php b/project/src/model/mdl/MdlScientifique.php index 6ea01da..2e3aa9f 100644 --- a/project/src/model/mdl/MdlScientifique.php +++ b/project/src/model/mdl/MdlScientifique.php @@ -37,4 +37,7 @@ class MdlScientifique extends MdlBase{ $difficulte, $sexe); } + public function addScientifique(Scientifique $s){ + return $this->gw->addScientifique($s); + } } \ No newline at end of file diff --git a/project/src/model/mdl/MdlSexe.php b/project/src/model/mdl/MdlSexe.php index 0bb7362..beaf9d8 100644 --- a/project/src/model/mdl/MdlSexe.php +++ b/project/src/model/mdl/MdlSexe.php @@ -14,9 +14,9 @@ class MdlSexe extends MdlBase{ $row = $this->gw->getFromId($id); return new Sexe($row['id'], $row['libelle']); } - public function getSexes(): array { + public function getAll(): array { $ret=array(); - $row = $this->gw->getSexes(); + $row = $this->gw->getAll(); for($i=0; $i< count($row); $i++){ array_push($ret, new Sexe($row[$i]['id'], $row[$i]['libelle'])); } diff --git a/project/src/model/mdl/MdlThematique.php b/project/src/model/mdl/MdlThematique.php index d09f2ca..e477104 100644 --- a/project/src/model/mdl/MdlThematique.php +++ b/project/src/model/mdl/MdlThematique.php @@ -14,4 +14,13 @@ class MdlThematique extends MdlBase{ $row = $this->gw->getFromId($id); return new Thematique($row['id'], $row['libelle']); } + + public function getAll(): array { + $ret=array(); + $row = $this->gw->getAll(); + for($i=0; $i< count($row); $i++){ + array_push($ret, new Thematique($row[$i]['id'], $row[$i]['libelle'])); + } + return $ret; + } } \ No newline at end of file From e403b69a81be4ea1704c31a602e5bc8eb9396414 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Mon, 20 Nov 2023 19:00:48 +0100 Subject: [PATCH 4/7] ajouter page admin "ajouter Scientifiques" --- project/src/controller/AdminController.php | 51 +++++++++--- project/src/templates/admin/accueil.html | 26 ++++++ .../templates/admin/ajouterScientifiques.html | 83 +++++++++++++++++++ 3 files changed, 147 insertions(+), 13 deletions(-) create mode 100644 project/src/templates/admin/accueil.html create mode 100644 project/src/templates/admin/ajouterScientifiques.html diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index aadb0db..eae9b74 100644 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -1,6 +1,11 @@ render('admin/accueil.html'); + echo $twig->render('admin/accueil.html'); break; case 'stats': - echo "stats admin";exit; - // echo $twig->render('admin/stats.html'); + echo $twig->render('admin/stats.html'); break; case 'ajouterScientifiques': - echo "page ajout scientifiques admin";exit; - // echo $twig->render('admin/ajouter.html'); + $sexe = new MdlSexe(); + $theme = new MdlThematique(); + $diff = new MdlDifficulte(); + if(!empty($_POST)){ + $sci=new MdlScientifique(); + $sci->addScientifique(new Scientifique(0, + $_POST["name"], + $_POST["prenom"], + $_POST["url"], + \DateTime::createFromFormat("Y-m-d",$_POST["date"]), + $_POST["description"], + 0, + $theme->getFromId(intval($_POST["theme"])), + $diff->getFromId(intval($_POST["difficulte"])), + $sexe->getFromId(intval($_POST["sexe"])) + )); + } + echo $twig->render('admin/ajouterScientifiques.html',['sexe' => $sexe->getAll(), 'themes' => $theme->getAll(), 'difficultes' => $diff->getAll()]); break; //mauvaise action default: @@ -42,18 +61,24 @@ class AdminController { } } } - //verifier si l'utilisateur est connecté mais pas admin - if(isset($_SESSION["isLogged"])){ + else if(isset($_SESSION["isLogged"])){ + //verifier si l'utilisateur est connecté mais pas admin if($_SESSION["isLogged"]==true) { - //dire acces interdit au non admins - array_push($dVueEreur, "Erreur 403 : Acces interdit"); + //dire acces interdit aux non admins + $dVueErreur[] = 'Erreur 403 : Accès interdit !'; echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); exit(0); } - } - //renvoyer a la page de connexion pour les non connectés - echo $twig->render('login.html'); + } else { + //renvoyer a la page de connexion pour les non connectés + echo ''; + } exit(0); } + } + + + + ?> \ No newline at end of file diff --git a/project/src/templates/admin/accueil.html b/project/src/templates/admin/accueil.html new file mode 100644 index 0000000..71ebfb5 --- /dev/null +++ b/project/src/templates/admin/accueil.html @@ -0,0 +1,26 @@ + + + + + + + + Accueil + + + +

Bienvenue sur Mini-Console Admin

+

{{dVue.pseudo}}

+



+
+ Ajouter Scientifiques +
+ + + + + diff --git a/project/src/templates/admin/ajouterScientifiques.html b/project/src/templates/admin/ajouterScientifiques.html new file mode 100644 index 0000000..82e80d9 --- /dev/null +++ b/project/src/templates/admin/ajouterScientifiques.html @@ -0,0 +1,83 @@ + + + + + Créer une partie + + + + +

ajouterScientifiques

+ +


+ +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ Sexe : + {% for se in sexe %} +
+ + +
+ {% endfor %} +
+
+ Thematique : + {% for se in themes %} +
+ + +
+ {% endfor %} +
+
+ Difficulté : + {% for se in difficultes %} +
+ + +
+ {% endfor %} +
+ + + + +
+
+ + + + \ No newline at end of file From c8323d3f50249c42343e9005cb070adcefc62b28 Mon Sep 17 00:00:00 2001 From: Renaud BEURET Date: Tue, 21 Nov 2023 13:37:28 +0100 Subject: [PATCH 5/7] finition correction altorouteur --- .idea/deployment.xml | 0 project/src/config/config.php | 7 +++- project/src/controller/FrontController.php | 46 ++------------------- project/src/controller/JouerController.php | 9 ++-- project/src/controller/PseudoController.php | 5 ++- project/src/controller/UserController.php | 30 +++++++++++++- project/src/index.php | 6 ++- 7 files changed, 51 insertions(+), 52 deletions(-) mode change 100644 => 100755 .idea/deployment.xml mode change 100644 => 100755 project/src/controller/JouerController.php diff --git a/.idea/deployment.xml b/.idea/deployment.xml old mode 100644 new mode 100755 diff --git a/project/src/config/config.php b/project/src/config/config.php index cd6acdd..4194993 100755 --- a/project/src/config/config.php +++ b/project/src/config/config.php @@ -6,5 +6,10 @@ $config = [ "db" => ["dsn" => 'pgsql:host=localhost;dbname=dbrebeuret', "login" => 'rebeuret', - "mdp" => 'achanger'] + "mdp" => 'achanger'], + "templates" => ["index" => 'vues/index.php', + "pseudo" => 'pseudo.html', + "jouer" => "jouer.html", + "pendu" => "pendu.html", + "penduScore" => 'penduScore.html'] ]; \ No newline at end of file diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 959e608..1b6b1f1 100755 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -32,17 +32,9 @@ class FrontController $router = new AltoRouter(); $router->setBasePath($basePath); - $router->map('GET|POST','/[a:action]?','UserController'); + $router->map('GET|POST','/pseudo/[a:action]?','PseudoController'); $router->map('GET|POST','/admin/[a:action]','AdminController'); - - $router->map('GET|POST', '/validationFormulaire', 'validationFormulaire'); - $router->map('GET|POST', '/logout', 'disconnect'); - - - // Tableau qui contient les messages d'erreur - $dVueErreur = []; - $dVue = []; - $dVue['basePath'] = $basePath; + $router->map('GET|POST','/[a:action]?','UserController'); session_start(); @@ -74,10 +66,6 @@ class FrontController $this->callController('PseudoController',$match); break; - case 'validationFormulaire': - $this->ValidationFormulaire($dVueErreur, $dVue); - break; - //mauvaise action default: $dVueErreur[] = "Erreur d'appel php"; @@ -104,7 +92,7 @@ class FrontController $controller = '\\controller\\'.$cont; $controller = new $controller; - $action = $match['params']['action'] ?? 'accueil'; + $action = $match['params']['action'] ?? 'defaultAction'; if (is_callable(array($controller,$action))) { call_user_func_array(array($controller,$action),array($match['params'])); @@ -112,32 +100,4 @@ class FrontController echo $twig->render('erreur.html', ['dVueErreur' => array('Page inconnue')]); } } - - public function ValidationFormulaire(array &$dVueErreur, array &$dVue) - { - global $twig; - - $id_jeu = $_POST['jeu'] ?? ''; - $id_difficulte = $_POST['difficulte'] ?? ''; - try{ - Validation::val_form($id_jeu, $id_difficulte, $dVueErreur); - }catch (ValidationException|Exception $ex){ - $this->CreateParty($dVueErreur); - } - - if(count($dVueErreur) == 0){ - $jeu = (new MdlJeu())->getFromId($id_jeu); - $difficulte = (new MdlDifficulte())->getFromId($id_difficulte); - $_SESSION['configuration'] = new ConfigurationJeu($jeu, $difficulte); - - header("Location: /pseudo"); - #echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); - }else{ - $this->CreateParty($dVueErreur); - } - } - - private function CreateParty(array $dVueErreur) - { - } } diff --git a/project/src/controller/JouerController.php b/project/src/controller/JouerController.php old mode 100644 new mode 100755 index bb55cb2..22922f3 --- a/project/src/controller/JouerController.php +++ b/project/src/controller/JouerController.php @@ -12,8 +12,9 @@ class JouerController{ */ public function __construct(){ global $twig, $config; - $dVue = []; - $dVueErreur = []; + global $dVue; + global $dVueErreur; + global $basePath; if(isset($_SESSION["configuration"]) && isset($_SESSION['role'])){ try{ @@ -22,7 +23,7 @@ class JouerController{ $configurationJeu = $_SESSION['configuration']; $configurationJeu = Validation::valConfigurationJeu($configurationJeu, $dVueErreur); }catch(ValidationException $e){ - header('Location: .'); + header('Location: '.$basePath); } if(count($dVueErreur) == 0){ @@ -36,7 +37,7 @@ class JouerController{ } } }else{ - header("Location: ."); + header("Location: ".$basePath); } } } \ No newline at end of file diff --git a/project/src/controller/PseudoController.php b/project/src/controller/PseudoController.php index 9b3c4cf..2b8c68f 100755 --- a/project/src/controller/PseudoController.php +++ b/project/src/controller/PseudoController.php @@ -9,8 +9,9 @@ use model\MdlInvite; class PseudoController{ - public function __construct(){ + public function defaultAction(){ global $twig, $config; + global $basePath; $dVue = []; $dVueErreur = []; @@ -35,7 +36,7 @@ class PseudoController{ if(isset($role)){ $_SESSION['role'] = $role; - header('Location: jouer'); + header('Location: '.$basePath.'/jouer'); } } echo $twig->render($config['templates']['pseudo'], ["dVue" => $dVue, "dVueErreur" => $dVueErreur]); diff --git a/project/src/controller/UserController.php b/project/src/controller/UserController.php index a5ec0e4..f98983c 100755 --- a/project/src/controller/UserController.php +++ b/project/src/controller/UserController.php @@ -4,6 +4,7 @@ namespace controller; use config\Validation; use Exception; +use model\ConfigurationJeu; use model\Connection; use model\GameGateway; use model\MdlDifficulte; @@ -12,7 +13,7 @@ use model\ValidationException; class UserController { - public function accueil(array $params) { + public function defaultAction(array $params) { global $twig; echo $twig->render('accueil.html'); @@ -81,4 +82,31 @@ class UserController { echo $twig->render('create.html', ["dVueErreur" => $dVueErreur, 'dVueCreate' => ["jeux" => $dVueCreateJeu, "difficultes" => $dVueCreateDifficulte]]); } + + public function ValidationFormulaire(array $params) + { + global $twig; + global $dVue; + global $dVueErreur; + global $basePath; + + $id_jeu = $_POST['jeu'] ?? ''; + $id_difficulte = $_POST['difficulte'] ?? ''; + try{ + Validation::val_form($id_jeu, $id_difficulte, $dVueErreur); + }catch (ValidationException|Exception $ex){ + $this->CreateParty($dVueErreur); + } + + if(count($dVueErreur) == 0){ + $jeu = (new MdlJeu())->getFromId($id_jeu); + $difficulte = (new MdlDifficulte())->getFromId($id_difficulte); + $_SESSION['configuration'] = new ConfigurationJeu($jeu, $difficulte); + + header("Location: ".$basePath."/pseudo"); + #echo $twig->render('accueil.html', ['dVue' => $dVue, 'dVueErreur' => $dVueErreur]); + }else{ + $this->CreateParty($dVueErreur); + } + } } \ No newline at end of file diff --git a/project/src/index.php b/project/src/index.php index 06d9e3c..f88cb65 100755 --- a/project/src/index.php +++ b/project/src/index.php @@ -12,8 +12,12 @@ 'cache' => false, ]); - $dVueErreur = array(); $basePath = preg_replace('/\/index.php/i', '', $_SERVER['PHP_SELF']); + // Tableau qui contient les messages d'erreur + $dVueErreur = []; + $dVue = []; + $dVue['basePath'] = $basePath; + $cont = new FrontController(); \ No newline at end of file From 7dd4ab91935275b36d2c92e0f053717663b0f4ec Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Tue, 21 Nov 2023 14:04:50 +0100 Subject: [PATCH 6/7] Ajout route index.php --- project/src/controller/FrontController.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 1b6b1f1..4ac6447 100755 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -31,6 +31,9 @@ class FrontController //altorouter $router = new AltoRouter(); $router->setBasePath($basePath); + + // Correspond à action = null et permet d'éviter une erreur sur la page /index.php + $router->map('GET|POST','/index.php','UserController'); $router->map('GET|POST','/pseudo/[a:action]?','PseudoController'); $router->map('GET|POST','/admin/[a:action]','AdminController'); From fe8842a1902cb1ba1911df63f8823893b5316c41 Mon Sep 17 00:00:00 2001 From: "gwenael.planchon" Date: Tue, 21 Nov 2023 15:14:45 +0100 Subject: [PATCH 7/7] fix dvue --- project/src/controller/FrontController.php | 3 +-- project/src/controller/UserController.php | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 781c26a..4ea36d4 100755 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -25,7 +25,7 @@ class FrontController public function __construct() { - global $twig, $router; + global $twig, $router, $dVue; global $basePath; //altorouter @@ -38,7 +38,6 @@ class FrontController $router->map('GET|POST','/pseudo/[a:action]?','PseudoController'); $router->map('GET|POST','/admin/[a:action]','AdminController'); $router->map('GET|POST','/[a:action]?','UserController'); - $router->map('GET|POST','/login','login'); session_start(); diff --git a/project/src/controller/UserController.php b/project/src/controller/UserController.php index f60a20d..d314d5e 100755 --- a/project/src/controller/UserController.php +++ b/project/src/controller/UserController.php @@ -17,9 +17,9 @@ use model\LoginException; class UserController { public function defaultAction(array $params) { - global $twig; + global $twig, $dVue; - echo $twig->render('accueil.html'); + echo $twig->render('accueil.html', ["dVue"=>$dVue]); } public function joinParty(array $params) {