Ajout de la page de login
continuous-integration/drone/push Build is passing Details

interestingProfiles
johan 2 years ago
parent 0057b45129
commit 35d9d19646

@ -1,5 +1,6 @@
<?php
namespace Config;
class Autoload
{
private static $instance = null;

@ -1,6 +1,6 @@
<?php
namespace Config\DataManagement;
namespace Config;
class Clean
{

@ -1,6 +1,6 @@
<?php
namespace Config\DataManagement;
namespace Config;
class Validate
{

@ -5,8 +5,17 @@ $rep = __DIR__ . '/../';
$views['form'] = 'Views/HTML/form.php';
$views['admin'] = 'Views/HTML/admin.php';
$views['adminLogin'] = 'Views/HTML/adminLogin.php';
$views['possibleResponsesForm'] = 'Views/HTML/possibleResponsesForm.php';
$views['continue'] = 'Views/HTML/continue.php';
$views['error'] = 'Views/HTML/error.php';
$controller['Candidate'] = 'ControllerCandidate';
$controller['Admin'] = 'ControllerAdmin';
$error['404'] = "La page demandée n'existe pas";
$error['403'] = "Vous n'avez pas les droits pour accéder à cette page";
$error['500'] = "Une erreur est survenue";
$googleApis = "https://fonts.googleapis.com";
$googleStatic = "https://fonts.gstatic.com";
@ -14,6 +23,8 @@ $poppins = "https://fonts.googleapis.com/css2?family=Poppins:wght@300&display=sw
$icon = "https://cdn.uca.fr/images/favicon/favicon.ico";
$logoUCA = "https://cdn.uca.fr/images/logos/logo_uca_mini_light.png";
$_SERVER['BASE_URI'] = "";
$emailMaxLength=150;
$pseudoMaxLength=50;
$passwordMaxLength=500;

@ -18,11 +18,17 @@ class ControllerCandidate
public function goToForm(): void
{
global $rep, $views;
$html = (new ModelCandidate())->getForm();
//$html = (new ModelCandidate())->getForm();
require_once($rep.$views['form']);
}
public function goToAdminLogin(): void
{
global $rep, $views;
require_once($rep.$views['adminLogin']);
}
/**
* Permet de finaliser la saisie du formulaire et de le soumettre.
*

@ -4,37 +4,68 @@ namespace Controller;
use Exception;
use PDOException;
use Config\DataManagement;
use Config\Validate;
use Config\Clean;
use Config\AltoRouter;
/**
* Permet de gérer l'appel des controllers en fonction de l'action et du rôle de l'utilisateur
*/
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();
class FrontController {
private $router;
private $rights;
public function __construct() {
$this->router = new AltoRouter();
$this->router->setBasePath($_SERVER['BASE_URI']);
$this->mapRoutes();
$this->rights = array (
'Candidate' => array('ControllerCandidate'),
'Admin' => array('ControllerCandidate','ControllerAdmin')
);
}
try {
$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
public function run() {
global $error,$rep,$views;
$exists=false;
$match = $this->router->match();
if ($match) {
$target = $match['target'];
$params = $match['params'];
if(!isset($_SESSION['role'])) {
$_SESSION['role'] = 'Candidate';
}
$role = Clean::simpleString($_SESSION['role']);
foreach($this->rights[$role] as $controllerName) {
if(strcmp($controllerName,$target[0])===0) {
$controllerClass = '\Controller\\' . $target[0];
$controller = new $controllerClass();
$controller->{$target[1]}($params);
$exists=true;
}
}
} catch (PDOException|Exception $e) {
$dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur
echo "ERREUUUUUR";
if(!$exists) {
$error = $error['403'];
require_once($rep . $views['error']);
}
} else {
// no route was matched
$error = $error['404'];
require_once($rep . $views['error']);
}
}
exit(0);
private function mapRoutes() {
global $controller;
$this->router->map('GET', '/', array($controller['Candidate'], 'goToForm'), 'goToForm');
$this->router->map('POST', '/submitForm', array($controller['Candidate'], 'submitForm'), 'submitForm');
$this->router->map('POST', '/addQuestion', array($controller['Admin'], 'addQuestion'), 'addQuestion');
$this->router->map('POST', '/addResponse', array($controller['Admin'], 'addResponse'), 'addResponse');
$this->router->map('POST','/continueResponse',array($controller['Admin'],'continueResponse'),'continueResponse');
$this->router->map('POST','/createForm',array($controller['Admin'],'createForm'),'createForm');
$this->router->map('POST','/addKeyword',array($controller['Admin'],'addKeyword'),'addKeyword');
$this->router->map('GET','/goToAdmin',array($controller['Admin'],'goToAdmin'),'goToAdmin');
$this->router->map('GET','/goToAdminLogin',array($controller['Candidate'],'goToAdminLogin'),'goToLogin');
}
}

@ -13,6 +13,15 @@ use BusinessClass\Form;
*/
class ModelAdmin
{
public function goToAdmin(): void
{
global $rep, $views;
try{
require_once($rep . $views['admin']);
} catch (PDOException $e) {
$error = $e->getMessage();
require_once($rep . $views['form']);
}
/**
* Permet de créer et d'ajouter une question et de retourner son ID afin de la reconnaitre facilement dans
* la suite du code.

@ -19,7 +19,7 @@
<img id="logoUCA" src="<?php echo $logoUCA; ?>" height="35px" width="auto" alt="logo UCA">
<?php echo $html; ?>
<?php //echo $html; ?>
</body>

@ -1,8 +1,9 @@
<?php
use Controller\FrontController;
use Config\Autoload;
require_once(__DIR__ . "/API/script/Config/config.php");
require_once(__DIR__.'/Config/Autoload.php');
require_once(__DIR__.'/Config/config.php');
require_once(__DIR__.'/Config/Autoload.php');
Autoload::charger();
@ -10,3 +11,4 @@ Autoload::charger();
session_start();
$frontController = new FrontController();
$frontController->run();

Loading…
Cancel
Save