Intermédiaire
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/**
|
||||
* This file is the entry point of phpAduc.
|
||||
*
|
||||
* Ce fichier redirige les demandes vers la page appropriée
|
||||
* This file switch to appropriate module
|
||||
*
|
||||
* PHP version > 7.3
|
||||
*
|
||||
@@ -20,46 +20,101 @@
|
||||
* @version GIT: 2.0
|
||||
* @link ../tests/Documentation Tests/Documentation.odt
|
||||
*/
|
||||
// Charge les classes installées par Composer
|
||||
// load composer's classes
|
||||
require_once 'vendor/autoload.php';
|
||||
// Lire la configuration du site
|
||||
// Site's configuration
|
||||
require_once 'src/config/config.php';
|
||||
// load local classes
|
||||
require_once 'src/class/autoload.php';
|
||||
session_start();
|
||||
|
||||
/* Initialisation de Smarty */
|
||||
/* Smarty initialization */
|
||||
$smarty = new Smarty();
|
||||
// Définir le dossier templates
|
||||
// Define template's forlder
|
||||
$smarty->setTemplateDir('src/templates');
|
||||
$smarty->setConfigDir('src/templates/configs');
|
||||
|
||||
// Définir le dossier qui recoit les templates compilés
|
||||
// Define compiled templates folder target
|
||||
$smarty->setCompileDir('templates_c');
|
||||
$smarty->setCacheDir('src/templates_c/cache');
|
||||
|
||||
// Lire la page demandée
|
||||
$smarty->assign('Title',"easyCloud");
|
||||
echo $smarty->display("main.smarty");
|
||||
|
||||
|
||||
die();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// read task wanted
|
||||
$Action=filter_input(INPUT_POST,'Action',FILTER_SANITIZE_STRING);
|
||||
if(!isset($_SESSION['Loggued']) && $Action=="")
|
||||
{
|
||||
$Action='Login';
|
||||
|
||||
// Read token (in aduc's cookie)
|
||||
if( isset($_COOKIE['aduc']) )
|
||||
{ // got one
|
||||
if( $Action == ""){ // No Action specified -> display main page
|
||||
$Action="main";
|
||||
}
|
||||
// Compare actual time with TimeOut in redis values -> know if token is still valid
|
||||
$redis = new Redis();
|
||||
$redis->connect($Cfg['redishost'], 6379);
|
||||
// Read variables designed by the token
|
||||
$aUser = json_decode($redis->get($_COOKIE['aduc']));
|
||||
if( time() > strtotime($aUser->TimeOut))
|
||||
{
|
||||
// Token is not valid anymore, force login
|
||||
$redis->unlink($_COOKIE['aduc']);
|
||||
setcookie("aduc","",time() - 3600);
|
||||
$Action = "Login";
|
||||
}
|
||||
|
||||
} else {
|
||||
// No token available
|
||||
if( $Action != "tryLogin" ){
|
||||
// Action is not tryLogin, we don't have a token -> force login
|
||||
$Action='Login';
|
||||
}
|
||||
}
|
||||
|
||||
error_log("Appel avec $Action");
|
||||
|
||||
|
||||
switch($Action)
|
||||
{
|
||||
case 'tryLogin':
|
||||
error_log('tryLogin ');
|
||||
$Usr=new userClass();
|
||||
$sLogin=filter_input(INPUT_POST,'sLogin',FILTER_SANITIZE_STRING);
|
||||
$sPasswd=filter_input(INPUT_POST,'sPassword',FILTER_SANITIZE_STRING);
|
||||
if($Usr->isValid($sLogin,$sPasswd))
|
||||
{
|
||||
$template='main.smarty';
|
||||
$component='main';
|
||||
$_SESSION['loggued']=true;
|
||||
if($Usr->isValid($Cfg, $sLogin,$sPasswd))
|
||||
{ // User type good credentials
|
||||
|
||||
// Get a new token
|
||||
$TOKEN = uniqid("aduc_",true);
|
||||
// put it in a cookie
|
||||
setcookie("aduc",$TOKEN,time()+$Cfg['delay']);
|
||||
// Save session on redis server
|
||||
$User = ["Login" => $sLogin, "Password" => $sPasswd, "Start" => date('Y-m-d H:i:s',time()), "TimeOut" => date('Y-m-d H:i:s',time()+3600)];
|
||||
$redis = new Redis();
|
||||
$redis->connect($Cfg['redishost'], 6379);
|
||||
$redis->set($TOKEN,json_encode($User));
|
||||
// load main page
|
||||
$template='main.smarty';
|
||||
$component='main';
|
||||
}
|
||||
else
|
||||
{
|
||||
{ // login fail -> display login page
|
||||
$template='login.smarty';
|
||||
$component="";
|
||||
$smarty->assign('error','Compte ou mot de passe invalide !');
|
||||
@@ -68,7 +123,11 @@ switch($Action)
|
||||
break;
|
||||
|
||||
case 'Logout':
|
||||
unset($_SESSION['Loggued']);
|
||||
$redis = new Redis();
|
||||
$redis->connect($Cfg['redishost'], 6379);
|
||||
$redis->unlink($_COOKIE['aduc']);
|
||||
setcookie("aduc","",time() - 3600);
|
||||
error_log("unset cookie");
|
||||
|
||||
case 'Login':
|
||||
$template='login.smarty';
|
||||
|
||||
Reference in New Issue
Block a user