From 30fea99ed6f9f85d74c31033228e9f9bab327115 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 11 Apr 2016 14:22:08 +0200 Subject: [PATCH] Correction de gestion de date d'expiration pour les tokens --- manager/repo/token.php | 15 ++++++++------- view/js/settings.js | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/manager/repo/token.php b/manager/repo/token.php index 1de4a40..1843db0 100644 --- a/manager/repo/token.php +++ b/manager/repo/token.php @@ -102,7 +102,7 @@ =========================================================*/ $check = Database::getPDO()->prepare("SELECT id_token FROM api_token - WHERE CURDATE() < expires + WHERE CURDATE() <= expires AND token = :token"); $check->execute(array( ':token' => $token )); @@ -130,6 +130,8 @@ 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 =========================================================*/ @@ -150,14 +152,13 @@ /* [2] On cree le token =========================================================*/ $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( - ':token' => $token, - ':name' => $name, - ':duration' => $duration+1 + ':token' => $token, + ':name' => $name, + ':expiration' => $expiration )); - /* [3] On verifie qu'il a bien ete cree =========================================================*/ $created = Database::getPDO()->prepare("SELECT id_token FROM api_token @@ -165,7 +166,7 @@ AND name = :name"); $created->execute(array( ':token' => $token, - ':name' => $name + ':name' => $name )); $created_data = $created->fetch(); diff --git a/view/js/settings.js b/view/js/settings.js index e31f884..f3a5139 100644 --- a/view/js/settings.js +++ b/view/js/settings.js @@ -40,6 +40,7 @@ var TOKEN = { // On lance la requete api.send(request, function(answer){ + console.log(answer); // Si la generation effectuee, on recharge la page if( answer.ModuleError == 0 ) reload();