summaryrefslogtreecommitdiff
path: root/http/public/do/verify_otp.php
diff options
context:
space:
mode:
authorJoe Carstairs <me@joeac.net>2026-08-13 16:33:51 +0100
committerJoe Carstairs <me@joeac.net>2026-08-13 16:33:51 +0100
commit62e6bab910297aa15d76eb735ce3dd9b5417e26e (patch)
treea98b5fb2c2663e08c21475b1092ccec395e2d87e /http/public/do/verify_otp.php
parentf9272fdf3ea23070583c944b110a7b8f16c5a4ff (diff)
remove website/capsule content
Diffstat (limited to 'http/public/do/verify_otp.php')
-rw-r--r--http/public/do/verify_otp.php63
1 files changed, 0 insertions, 63 deletions
diff --git a/http/public/do/verify_otp.php b/http/public/do/verify_otp.php
deleted file mode 100644
index 7f86858..0000000
--- a/http/public/do/verify_otp.php
+++ /dev/null
@@ -1,63 +0,0 @@
-<?php
-
-use JoeacNet\Http\Db;
-
-require_once __DIR__ . "/../../php/db.php";
-
-$db = Db\connectDb();
-
-$payload = json_decode(file_get_contents("php://input"), true);
-$guess = getGuessFromPayloadAndValidate($payload);
-$leniencySecs = getLeniencySecsFromPayloadAndValidate($payload);
-$userId = getUserIdFromPayloadAndValidate($payload);
-
-if (
- !Db\isOtpCorrect(
- db: $db,
- userId: $userId,
- guess: $guess,
- leniencySecs: $leniencySecs,
- )
-) {
- http_response_code(400);
- echo "OTP is not valid";
- exit();
-}
-Db\deleteAllOtpsForUser($db, $userId);
-$token = bin2hex(random_bytes(256));
-Db\insertSendEmailToken(db: $db, userId: $userId, token: $token);
-http_response_code(200);
-echo $token;
-exit();
-
-/// functions ///
-
-function getGuessFromPayloadAndValidate(array $payload): string
-{
- $guess = (string) $payload["guess"];
- if (strlen($guess) != 6) {
- http_response_code(400);
- echo "guess must be six characters long";
- exit();
- }
- return $guess;
-}
-
-function getLeniencySecsFromPayloadAndValidate(array $payload): int
-{
- if ((bool) $payload["lenient"] ?? false) {
- return 60;
- }
- return 0;
-}
-
-function getUserIdFromPayloadAndValidate(array $payload): string
-{
- $userId = (string) $payload["userId"];
- if (is_null($userId) || $userId == "") {
- http_response_code(400);
- echo "userId must not be empty";
- exit();
- }
- return $userId;
-}