|
|
<?php
|
|
|
namespace Controleur;
|
|
|
|
|
|
use Gateway\Connection;
|
|
|
|
|
|
Class FrontControler{
|
|
|
|
|
|
private $listAction;
|
|
|
|
|
|
private Connection $co;
|
|
|
|
|
|
public function __construct($co){
|
|
|
global $twig;
|
|
|
|
|
|
$this->listAction = ['visitor' => array('accueil','search','quote','login','signin','validlogin','validsignin'),
|
|
|
'user' => array('quiz','commentary','logout','addComment','favorite','profil'),
|
|
|
'admin' => array('null')];
|
|
|
|
|
|
$dVueEreur = [];
|
|
|
|
|
|
$router = new \AltoRouter();
|
|
|
$router->setBasePath('/~kekentin/WF/WF-Website');
|
|
|
|
|
|
$router->map('GET', '/', 'VisitorControler','accueil');
|
|
|
|
|
|
/*
|
|
|
'i' => '[0-9]++'
|
|
|
'a' => '[0-9A-Za-z]++'
|
|
|
'h' => '[0-9A-Fa-f]++'
|
|
|
'*' => '.+?'
|
|
|
'**' => '.++'
|
|
|
'' => '[^/\.]++'
|
|
|
*/
|
|
|
|
|
|
|
|
|
$router->map('GET|POST', '/quote/[i:idQuote]', 'VisitorControler','quote');
|
|
|
$router->map('GET|POST', '/addComment', 'UserControler','addComment');
|
|
|
$router->map('GET|POST', '/quiz/[i:id]', 'UserControler','quiz');
|
|
|
$router->map('GET|POST', '/favorite', 'UserControler','favorite');
|
|
|
$router->map('GET|POST', '/search', 'VisitorControler','search');
|
|
|
$router->map('GET|POST', '/profil', 'UserControler','profil');
|
|
|
$router->map('GET|POST', '/login', 'VisitorControler','login');
|
|
|
$router->map('GET|POST', '/unlog', 'UserControler','unlog');
|
|
|
$router->map('GET|POST', '/signin', 'VisitorControler','signin');
|
|
|
$router->map('GET|POST', '/validlogin', 'VisitorControler','validlogin');
|
|
|
$router->map('GET|POST', '/validsignin', 'VisitorControler','validsignin');
|
|
|
|
|
|
|
|
|
$match = $router->match();
|
|
|
$action = NULL;
|
|
|
|
|
|
if(!$match){
|
|
|
$dVueEreur[] = "Requête introuvable";
|
|
|
$this->vueErreur($dVueEreur);
|
|
|
}
|
|
|
else{
|
|
|
$controller=$match['target'] ?? null;
|
|
|
|
|
|
$action = $match['name'];
|
|
|
|
|
|
//Si existe, on l’appelle
|
|
|
if(!$this->ifExisteAction($action)){
|
|
|
$dVueEreur[] = "Action introuvable";
|
|
|
$this->vueErreur($dVueEreur);
|
|
|
}
|
|
|
|
|
|
else if(!$this->verifDroit($action)){
|
|
|
$action='login';
|
|
|
$controller='VisitorControler';
|
|
|
}
|
|
|
|
|
|
$controller = '\\Controleur\\' . $controller;
|
|
|
$controller = new $controller($co);
|
|
|
if (is_callable(array($controller, $action))) {
|
|
|
call_user_func_array(array($controller, $action),
|
|
|
array($match['params']));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
private function ifExisteAction(string $action):bool {
|
|
|
if( in_array($action , $this->listAction['admin']) ||
|
|
|
in_array($action , $this->listAction['user']) ||
|
|
|
in_array($action , $this->listAction['visitor']) ) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private function verifDroit(string $action):bool {
|
|
|
if( in_array($action , $this->listAction['admin']) && $_SESSION["role"] == 'admin') return true;
|
|
|
elseif( in_array($action , $this->listAction['user']) && ($_SESSION["role"] == 'admin' || $_SESSION["role"] == 'user') ) return true;
|
|
|
elseif(in_array($action , $this->listAction['visitor']) && ($_SESSION["role"] == 'admin'|| $_SESSION["role"] == 'user'|| $_SESSION["role"] == 'visitor')) return true;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
private function vueErreur(array $dVueErreur){
|
|
|
global $vues;
|
|
|
echo "{$dVueErreur[0]}";
|
|
|
require_once $vues['erreur'];
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|