Commit 3fa29605175f26a506a6f5fd36ff85712bfabb86
1 parent
48fb7168
Vérification de la date du jeton
Showing
2 changed files
with
15 additions
and
9 deletions
Show diff stats
api/commun.php
... | ... | @@ -30,13 +30,24 @@ function donne($parametre) { // Vérifie si le paramètre est donné |
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | +function supprimerJeton($jeton) { | |
34 | + $requete = $db->prepare("DELETE FROM Sessions WHERE jeton=?"); | |
35 | + $requete->bind_param("s", $jeton); | |
36 | + $requete->execute(); | |
37 | + $requete->close(); | |
38 | +} | |
39 | + | |
33 | 40 | function verifierJeton($jeton) { |
34 | 41 | global $db, $login, $droit; |
35 | - $requete = $db->prepare("SELECT Utilisateurs.login, Utilisateurs.droit FROM Utilisateurs JOIN Sessions ON Utilisateurs.login=Sessions.utilisateur WHERE Sessions.jeton=?"); | |
42 | + $requete = $db->prepare("SELECT Utilisateurs.login, Utilisateurs.droit, UNIX_TIMESTAMP(Sessions.date) FROM Utilisateurs JOIN Sessions ON Utilisateurs.login=Sessions.utilisateur WHERE Sessions.jeton=?"); | |
36 | 43 | $requete->bind_param("s", $jeton); |
37 | 44 | $requete->execute(); |
38 | - $requete->bind_result($login, $droit); | |
39 | - if (!$requete->fetch()) { | |
45 | + $requete->bind_result($login, $droit, $date); | |
46 | + if ($requete->fetch()) { | |
47 | + if (time() > $date + JETON_DUREE) { | |
48 | + retour("jeton_expire"); | |
49 | + } | |
50 | + } else { | |
40 | 51 | retour("jeton_invalide"); |
41 | 52 | } |
42 | 53 | $requete->close(); | ... | ... |
api/utilisateur/deconnexion.php
... | ... | @@ -11,12 +11,7 @@ if (!donne("jeton")) { |
11 | 11 | |
12 | 12 | verifierJeton(donne("jeton")); |
13 | 13 | |
14 | -$jeton = donne("jeton"); | |
15 | - | |
16 | -$requete = $db->prepare("DELETE FROM Sessions WHERE jeton=?"); | |
17 | -$requete->bind_param("s", $jeton); | |
18 | -$requete->execute(); | |
19 | -$requete->close(); | |
14 | +supprimerJeton(donne("jeton")); | |
20 | 15 | |
21 | 16 | retour("ok"); |
22 | 17 | ... | ... |