Skip to content

Commit 4997ede

Browse files
committed
add token cleanup
1 parent 38aaf89 commit 4997ede

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

TODO

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
- [-] Auto-create-storage
4141
- [v] jtiStore
4242

43-
- [ ] Cleanup for expired verify tokens, password, deletion
44-
- [ ] Password requirements
43+
- [v] Cleanup for expired verify tokens, password, deletion
44+
- [v] Password requirements
4545

4646
----------------------
4747

config.php.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const KEYDIR = __DIR__ . "/keys/";
66
const FRONTENDDIR = __DIR__ . "/frontend/";
77
const DBPATH = __DIR__ . "/db/solid.db";
8+
const CLEANUP_FILE = __DIR__ . "/db/lastcleanup";
89

910
const MAILER = [
1011
"host" => "mailpit",

lib/User.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,5 +334,17 @@ public static function deleteAccount($email) {
334334
// FIXME: Delete storage;
335335
self::deleteAllowedClients($email);
336336
self::deleteUser($email);
337-
}
337+
}
338+
339+
public static function cleanupTokens() {
340+
self::connect();
341+
342+
$now = new \DateTime();
343+
$query = self::$pdo->prepare(
344+
'DELETE FROM verify WHERE expires < :now'
345+
);
346+
$query->execute([
347+
':now' => $now->getTimestamp()
348+
]);
349+
}
338350
}

www/idp/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@
379379
header($_SERVER['SERVER_PROTOCOL'] . " 404 Not found");
380380
break;
381381
}
382+
if (!file_exists(CLEANUP_FILE) || (filemtime(CLEANUP_FILE) < time())) {
383+
touch(CLEANUP_FILE, time() + 3600);
384+
User::cleanupTokens();
385+
}
382386
break;
383387
case "OPTIONS":
384388
break;

0 commit comments

Comments
 (0)