Correction de gestion de date d'expiration pour les tokens
This commit is contained in:
parent
f227d44f7b
commit
30fea99ed6
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue