From 5393854b133a47a2270f00a29ece16cf5e0aef1b Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Thu, 23 Feb 2023 18:02:36 +0100 Subject: [PATCH] =?UTF-8?q?Changement=20du=20FrontController=20pour=20que?= =?UTF-8?q?=20les=20camarades=20de=20projets=20puissent=20=C3=A0=20nouveau?= =?UTF-8?q?=20acc=C3=A9der=20=C3=A0=20la=20page=20d'administration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/Controller/FrontController.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Source/Controller/FrontController.php b/Source/Controller/FrontController.php index 3523392..e621ca1 100644 --- a/Source/Controller/FrontController.php +++ b/Source/Controller/FrontController.php @@ -15,28 +15,26 @@ class FrontController * Définit le comportement de la classe à sa création, on appelle le bon controller en fonction de l'action * et du rôle de la personne qui souhaite réaliser cette action (utilisateur, administrateur...). */ + public function __construct() { + $listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin"); + global $rep, $views; $dVueError = array(); - $controllerPath = "\\Controller\\Controller"; - $mapRoleAccess = array( - "Candidate" => array("Candidate"), - "Admin" => array("Candidate", "Admin")); - if (!isset($_SESSION["role"])) - $currentRole = "Candidate"; - else $currentRole = Clean::simpleString($_SESSION["role"]); + try { - $action = isset($_REQUEST['action']) ? Clean::simpleString($_REQUEST['action']) : (new ControllerCandidate())->goToForm(); - foreach ($mapRoleAccess[$currentRole] as $role) { - if (method_exists($controllerPath . $role, $action)) { - (new $controllerPath . $role)->$action(); // Si oui, on appelle cette fonction + $action = $_REQUEST['action'] ? $action = $_REQUEST['action'] : (new ControllerCandidate())->goToForm(); + foreach ($listControllers as $controller) { + if (method_exists($controller, $action)) { + (new $controller)->$action(); // Si oui, on appelle cette fonction } } } catch (PDOException|Exception $e) { $dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur echo "ERREUUUUUR"; } + exit(0); } } \ No newline at end of file