From d82e0fdaf3c7315986acf4023588833af68e8c83 Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Mon, 2 Dec 2024 21:37:40 -0600 Subject: [PATCH] get rid of src/util --- src/{util => }/auth.php | 0 src/bootstrap.php | 6 ++--- src/{util => }/components.php | 0 src/{util => }/enums.php | 0 src/models/token.php | 50 ----------------------------------- 5 files changed, 3 insertions(+), 53 deletions(-) rename src/{util => }/auth.php (100%) rename src/{util => }/components.php (100%) rename src/{util => }/enums.php (100%) delete mode 100644 src/models/token.php diff --git a/src/util/auth.php b/src/auth.php similarity index 100% rename from src/util/auth.php rename to src/auth.php diff --git a/src/bootstrap.php b/src/bootstrap.php index e6c1ed2..2765598 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -14,9 +14,9 @@ define('CLASS_MAP', [ ]); require_once SRC . '/helpers.php'; -require_once SRC . '/util/auth.php'; -require_once SRC . '/util/components.php'; -require_once SRC . '/util/enums.php'; +require_once SRC . 'auth.php'; +require_once SRC . 'components.php'; +require_once SRC . 'enums.php'; require_once SRC . '/models/token.php'; diff --git a/src/util/components.php b/src/components.php similarity index 100% rename from src/util/components.php rename to src/components.php diff --git a/src/util/enums.php b/src/enums.php similarity index 100% rename from src/util/enums.php rename to src/enums.php diff --git a/src/models/token.php b/src/models/token.php deleted file mode 100644 index c5cfb37..0000000 --- a/src/models/token.php +++ /dev/null @@ -1,50 +0,0 @@ -query("INSERT INTO tokens (token, user_id) VALUES (:t, :u)", [ - ':t' => $token, - ':u' => $userId - ]); - if (!$result) return false; - return $token; -} - -/** - * Find a token by token. - */ -function token_find($token) -{ - $result = auth_db()->query("SELECT * FROM tokens WHERE token = :t", [':t' => $token]); - $token = $result->fetchArray(SQLITE3_ASSOC); - if (!$token) return false; - $result->finalize(); - return $token; -} - -/** - * Delete a token by token. - */ -function token_delete($token) -{ - return auth_db()->query("DELETE FROM tokens WHERE token = :t", [':t' => $token]); -} - -/** - * Validate a token by token and created date. Tokens are invalid if older than 7 days. - */ -function token_validate($token) -{ - $token = token_find($token); - if (!$token) return false; - if (strtotime('+7 days') < time()) { - token_delete($token['token']); - return false; - } - return true; -} -