Correction de gestion de date d'expiration pour les tokens

This commit is contained in:
xdrm-brackets 2016-04-11 14:22:08 +02:00
parent f227d44f7b
commit 30fea99ed6
2 changed files with 9 additions and 7 deletions

View File

@ -102,7 +102,7 @@
=========================================================*/ =========================================================*/
$check = Database::getPDO()->prepare("SELECT id_token $check = Database::getPDO()->prepare("SELECT id_token
FROM api_token FROM api_token
WHERE CURDATE() < expires WHERE CURDATE() <= expires
AND token = :token"); AND token = :token");
$check->execute(array( ':token' => $token )); $check->execute(array( ':token' => $token ));
@ -130,6 +130,8 @@
if( !Database::check('varchar(50)', $name) || !Database::check('int', $duration) ) return false; if( !Database::check('varchar(50)', $name) || !Database::check('int', $duration) ) return false;
// On definit la date d'expiration du token
$expiration = date('Y-m-d', time()+$duration*3600*24);
/* [1] Generation d'un token si pas deja dans la BDD /* [1] Generation d'un token si pas deja dans la BDD
=========================================================*/ =========================================================*/
@ -150,14 +152,13 @@
/* [2] On cree le token /* [2] On cree le token
=========================================================*/ =========================================================*/
$create = Database::getPDO()->prepare("INSERT INTO api_token(id_token, token, name, expires) $create = Database::getPDO()->prepare("INSERT INTO api_token(id_token, token, name, expires)
VALUES(DEFAULT, :token, :name, DATEADD(day, :duration, NOW()) )"); VALUES(DEFAULT, :token, :name, :expiration)");
$create->execute(array( $create->execute(array(
':token' => $token, ':token' => $token,
':name' => $name, ':name' => $name,
':duration' => $duration+1 ':expiration' => $expiration
)); ));
/* [3] On verifie qu'il a bien ete cree /* [3] On verifie qu'il a bien ete cree
=========================================================*/ =========================================================*/
$created = Database::getPDO()->prepare("SELECT id_token FROM api_token $created = Database::getPDO()->prepare("SELECT id_token FROM api_token

View File

@ -40,6 +40,7 @@ var TOKEN = {
// On lance la requete // On lance la requete
api.send(request, function(answer){ api.send(request, function(answer){
console.log(answer);
// Si la generation effectuee, on recharge la page // Si la generation effectuee, on recharge la page
if( answer.ModuleError == 0 ) if( answer.ModuleError == 0 )
reload(); reload();