From 62e6bab910297aa15d76eb735ce3dd9b5417e26e Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Thu, 13 Aug 2026 16:33:51 +0100 Subject: remove website/capsule content --- http/php/db.php | 205 -------------------------------------------------------- 1 file changed, 205 deletions(-) delete mode 100644 http/php/db.php (limited to 'http/php/db.php') diff --git a/http/php/db.php b/http/php/db.php deleted file mode 100644 index a60d6c4..0000000 --- a/http/php/db.php +++ /dev/null @@ -1,205 +0,0 @@ -exec( - <<exec( - <<exec( - <<query( - <<= $twentyFourHoursAgo; - SQL - , - ) - ->fetchColumn(0); -} - -function insertSendEmailToken(PDO $db, string $userId, string $token) -{ - $createdAtUnixSecs = time(); - $validUntilUnixSecs = $createdAtUnixSecs + 60; - $db - ->prepare( - <<execute([ - "userId" => $userId, - "token" => $token, - "createdAtUnixSecs" => $createdAtUnixSecs, - "validUntilUnixSecs" => $validUntilUnixSecs, - ]); -} - -function isTokenValid(PDO $db, string $userId, string $token): int -{ - $now = time(); - $stmt = $db->prepare( - <<= :validUntilUnixSecs; - SQL - , - ); - $stmt->execute([ - "userId" => $userId, - "token" => $token, - "validUntilUnixSecs" => $now, - ]); - $validTokenCount = (int) $stmt->fetchColumn(0); - return $validTokenCount > 0; -} - -function deleteAllTokensForUser(PDO $db, string $userId) -{ - $db - ->prepare( - <<execute(["userId" => $userId]); -} - -function deleteAllOtpsForUser(PDO $db, string $userId) -{ - $db - ->prepare( - <<execute(["userId" => $userId]); -} - -function recordSentEmail(PDO $db, string $messageId) -{ - $now = time(); - $stmt = $db->prepare( - <<execute(["messageId" => $messageId, "now" => $now]); -} - -function insertOtp(PDO $db, string $userId, string $otp) -{ - $createdAtUnixSecs = time(); - $validUntilUnixSecs = $createdAtUnixSecs + 60 * 5; - $db - ->prepare( - <<execute([ - "userId" => $userId, - "otp" => $otp, - "createdAtUnixSecs" => $createdAtUnixSecs, - "validUntilUnixSecs" => $validUntilUnixSecs, - ]); -} - -function isOtpCorrect( - PDO $db, - string $userId, - string $guess, - int $leniencySecs, -): bool { - $stmt = $db->prepare( - <<= :validUntilUnixSecs - SQL - , - ); - $stmt->execute([ - "userId" => $userId, - "guess" => $guess, - "validUntilUnixSecs" => time() - $leniencySecs, - ]); - return $stmt->fetchColumn(0); -} -- cgit v1.2.3