2016-04-04 09:47:17 +00:00
|
|
|
<?php define('__ROOT__', dirname(__FILE__) );
|
|
|
|
|
|
|
|
require_once __ROOT__.'/manager/autoloader.php';
|
|
|
|
|
|
|
|
use \router\Router;
|
|
|
|
use \manager\ResourceDispatcher;
|
|
|
|
use \manager\ModuleRequest;
|
2016-04-13 11:37:36 +00:00
|
|
|
use \manager\ManagerError;
|
|
|
|
use \manager\Database;
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
/*******************************************/
|
|
|
|
/* DEBUGGER */
|
|
|
|
/*******************************************/
|
|
|
|
debug();
|
|
|
|
/*******************************************/
|
|
|
|
|
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [x] Gestion des utilisateurs
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Valeurs par defaut */
|
|
|
|
if( !isset($_SESSION['userid']) ) $_SESSION['userid'] = null;
|
|
|
|
if( !isset($_SESSION['username']) ) $_SESSION['username'] = null;
|
|
|
|
if( !isset($_SESSION['permission']) ) $_SESSION['permission'] = array();
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Gestion de la connection */
|
|
|
|
$login_vars = isset($_POST['login']) && Database::check('varchar(255)', $_POST['login']);
|
|
|
|
$login_vars = $login_vars && isset($_POST['password']) && Database::check('text', $_POST['password']);
|
|
|
|
|
|
|
|
// Status de login
|
|
|
|
$_SESSION['login_status'] = 'no';
|
|
|
|
|
|
|
|
// Si les parametres de connection, on essaie de connecter
|
|
|
|
if( $login_vars ){
|
|
|
|
$login = new ModuleRequest('users/login', array( 'login' => $_POST['login'], 'password' => $_POST['password'] ));
|
|
|
|
$login_ans = $login->dispatch();
|
|
|
|
|
|
|
|
// Si aucune erreur, on dit qu'on vient de se connecter
|
|
|
|
if( $login_ans->error == ManagerError::Success )
|
|
|
|
$_SESSION['login_status'] = 'logged';
|
|
|
|
else // Si on n'a pas les bonnes donnees
|
|
|
|
$_SESSION['login_status'] = 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Gestion de le deconnexion */
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
/* [0] On initialise le routeur
|
|
|
|
===================================================*/
|
|
|
|
$R = new Router( $_GET['url'] );
|
2016-04-13 11:37:36 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
/* [1] On cree les regles de routage
|
|
|
|
===================================================*/
|
|
|
|
// Racine -> page d'accueil
|
|
|
|
$R->get('/?', function(){ header('Location: /dashboard/'); });
|
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
|
|
|
|
/* [2] On recupere la liste des pages du site
|
|
|
|
=========================================================*/
|
|
|
|
$views = json_decode( ResourceDispatcher::getResource( 'f/json/views/conf', true ) );
|
|
|
|
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
// nomPage/arg1/arg2 -> inclusion de la page
|
2016-04-04 12:04:36 +00:00
|
|
|
$R->get('(?:'.implode('|', $views).')(?:/[\w-]+)*/?', function(){ include __ROOT__.'/view.php'; });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
// Dispatcher
|
2016-04-04 12:04:36 +00:00
|
|
|
$R->get('f(?:/([\w-]+))*/?', function(){ new ResourceDispatcher($_GET['url'], true); });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
// Api
|
|
|
|
$R->post('api/?', function(){
|
|
|
|
$request = ModuleRequest::fromPost($_POST);
|
|
|
|
$answer = $request->dispatch();
|
|
|
|
|
|
|
|
echo $answer->serialize();
|
|
|
|
});
|
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
// N'importe -> page d'accueil
|
|
|
|
$R->get('.+', function(){ header('Location: /dashboard/'); });
|
2016-04-13 11:37:36 +00:00
|
|
|
$R->post('.+', function(){ header('Location: /dashboard/'); });
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-13 11:37:36 +00:00
|
|
|
|
2016-04-04 12:04:36 +00:00
|
|
|
/* [3] On lance le routeur
|
2016-04-04 09:47:17 +00:00
|
|
|
===================================================*/
|
|
|
|
$R->run();
|
|
|
|
|
|
|
|
?>
|