fix route header home

php
Anthony RICHARD 1 year ago
parent acb6d1a79e
commit c7618a1a22

@ -19,7 +19,7 @@ class FrontController
$router = new \AltoRouter();
$router->setBasePath($altorouterPath);
$router->map('GET', '/', 'FrontController');
$router->map('GET', '/', 'User');
$router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'Admin');
$router->map('GET|POST', '/teacher/[i:id]/[a:action]?', 'Teacher');
$router->map('GET|POST', '/student/[i:id]/[a:action]?', 'Student');
@ -43,39 +43,31 @@ class FrontController
call_user_func_array(array($userCtrl, $action), array($match['params']));
}
else {
switch ($action) {
case null:
$this->home();
break;
if ($target == null) throw new Exception("pas de target");
default :
if ($target == null) throw new Exception("pas de target");
if (isset($_SESSION['login']) && isset($_SESSION['roles'])) {
if (isset($_SESSION['login']) && isset($_SESSION['roles'])) {
$_SESSION['login'] = strip_tags($_SESSION['login']);
for ($i=0 ; $i<count($_SESSION['roles']) ; $i++) $_SESSION['roles'][$i] = strip_tags($_SESSION['roles'][$i]);
$_SESSION['login'] = strip_tags($_SESSION['login']);
for ($i=0 ; $i<count($_SESSION['roles']) ; $i++) $_SESSION['roles'][$i] = strip_tags($_SESSION['roles'][$i]);
$mdl = '\\model\\Mdl' . $target;
$mdl = new $mdl;
$mdl = '\\model\\Mdl' . $target;
$mdl = new $mdl;
if (is_callable(array($mdl, 'is'))) {
global $user;
$user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles']));
if (is_callable(array($mdl, 'is'))) {
global $user;
$user = call_user_func_array(array($mdl, 'is'), array($_SESSION['login'], $_SESSION['roles']));
$controller = '\\controller\\' . $target . 'Controller';
$controller = new $controller;
if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
}
if ($target == 'User' && $action == null) $controller->home();
else if (!$user || $user->getId() != $id) throw new Exception("erreur 403 permission denied");
$controller = '\\controller\\' . $target . 'Controller';
$controller = new $controller;
if (is_callable(array($controller, $action)))
call_user_func_array(array($controller, $action), array($match['params']));
break;
}
else (new UserController())->login();
if (is_callable(array($controller, $action)))
call_user_func_array(array($controller, $action), array($match['params']));
}
}
else (new UserController())->login();
}
}
}
@ -85,15 +77,4 @@ class FrontController
echo $twig->render('erreur.html', ['dVueEreur' => $dVueEreur]);
}
}
public static function home(): void {
global $twig;
global $user;
if(isset($user)){
echo $twig->render('home.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles()]);
}
else{
echo $twig->render('home.html', );
}
}
}

@ -53,4 +53,15 @@ class UserController extends VisitorController
throw new Exception("invalid entries");
}
}
public function home(): void {
global $twig;
global $user;
if(isset($user)){
echo $twig->render('home.html', ['userID' => $user->getId(), 'userRole' => $user->getRoles()]);
}
else{
echo $twig->render('home.html', );
}
}
}
Loading…
Cancel
Save