diff --git a/project/src/.htaccess b/project/src/.htaccess new file mode 100755 index 0000000..7ded04e --- /dev/null +++ b/project/src/.htaccess @@ -0,0 +1,3 @@ +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule . index.php [L] \ No newline at end of file diff --git a/project/src/controller/AdminController.php b/project/src/controller/AdminController.php index d037554..aadb0db 100644 --- a/project/src/controller/AdminController.php +++ b/project/src/controller/AdminController.php @@ -4,11 +4,8 @@ use Exception; //gerer la connexion des admins class AdminController { - public function __construct(){ - //TODO actions, liste actions, actions autorisées + public function __construct(string $action){ global $twig; - //on démarre ou reprend la session, obtenir $_SESSION - session_start(); //on initialise un tableau d'erreur pour etre utilisé par la vue erreur $dVueEreur = []; @@ -17,17 +14,18 @@ class AdminController { if($_SESSION["isAdmin"]==true){ //donner la page admin a l'admin try { - $action = $_REQUEST['admin'] ?? null; - switch($action) { - case null: - echo $twig->render('admin/accueil.html'); + case '': + echo "accueil admin";exit; + // echo $twig->render('admin/accueil.html'); break; case 'stats': - echo $twig->render('admin/stats.html'); + echo "stats admin";exit; + // echo $twig->render('admin/stats.html'); break; case 'ajouterScientifiques': - echo $twig->render('admin/ajouter.html'); + echo "page ajout scientifiques admin";exit; + // echo $twig->render('admin/ajouter.html'); break; //mauvaise action default: diff --git a/project/src/controller/FrontController.php b/project/src/controller/FrontController.php index 3a052f1..a326544 100644 --- a/project/src/controller/FrontController.php +++ b/project/src/controller/FrontController.php @@ -9,9 +9,18 @@ class FrontController { public function __construct() { - global $twig; + global $twig, $router; + + //$con = new Connection("mysql:host=mysql;dbname=iut", "aljeudilem", "22061337"); + + $router->map('GET|POST', '/', 'null'); + $router->map('GET|POST', '/join', 'join'); + $router->map('GET|POST', '/create', 'create'); + $router->map('GET|POST', '/login', 'login'); + $router->map('GET|POST', '/admin/[a:action]?', 'admin'); + $router->map('GET|POST', '/validationFormulaire', 'validationFormulaire'); + $router->map('GET|POST', '/logout', 'disconnect'); - $con = new Connection("mysql:host=mysql;dbname=iut", "aljeudilem", "22061337"); // Tableau qui contient les messages d'erreur $dVueErreur = []; @@ -23,10 +32,17 @@ class FrontController $dVue['pseudo'] = $_SESSION['pseudo']; try { - $action = $_REQUEST['action'] ?? null; + $match = $router->match(); + if (!$match) { + throw new \Exception('Wrong call'); + } + $action=$match['params']['action'] ?? ""; + //$id=$match['params']['id'] ?? null; + + - switch($action) { - case null: + switch($match['target']) { + case 'null': echo $twig->render('accueil.html', ['dVue' => $dVue]); break; case 'join': @@ -39,7 +55,7 @@ class FrontController $this->ValidationFormulaire($dVueErreur, $dVue); break; case 'admin': - new AdminController(); + new AdminController($action); break; case 'login': if(empty($_SESSION) && !isset($_REQUEST['login'])) @@ -76,7 +92,7 @@ class FrontController echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); echo $twig->render('login.html'); } catch (\Exception $e2) { - $dVueErreur[] = 'Erreur inattendue !'; + $dVueErreur[] = 'Erreur inattendue !'.$e2->getMessage(); echo $twig->render('erreur.html', ['dVueErreur' => $dVueErreur]); } diff --git a/project/src/index.php b/project/src/index.php index 8bfc0b7..3e056ff 100644 --- a/project/src/index.php +++ b/project/src/index.php @@ -11,8 +11,15 @@ 'cache' => false, ]); + //altorouter + $router = new AltoRouter(); + $router->setBasePath('/public_html/ScienceQuest'); + + $cont = new FrontController(); + + /* try{