diff --git a/app/Controllers/VerificationController.php b/app/Controllers/VerificationController.php index 9bf13d0..87bc281 100644 --- a/app/Controllers/VerificationController.php +++ b/app/Controllers/VerificationController.php @@ -1,7 +1,7 @@ prepare("UPDATE $table SET is_verified = 1, verification_code = NULL WHERE id = ?"); + $update = $db->prepare("UPDATE $table SET is_verified = 1 WHERE id = ?"); $update->execute([$subscriber['id']]); Logger::info("Subscriber verified: ID {$subscriber['id']} via $type"); diff --git a/app/Services/TokenService.php b/app/Services/TokenService.php new file mode 100644 index 0000000..80fda19 --- /dev/null +++ b/app/Services/TokenService.php @@ -0,0 +1,48 @@ +generate($data, $secret); + if (!hash_equals($expected, $token)) { + return false; + } + + if ($timestamp !== null && abs(time() - $timestamp) > $ttlSeconds) { + return false; + } + + return true; + } +} diff --git a/app/Services/UnsubscribeTokenService.php b/app/Services/UnsubscribeTokenService.php new file mode 100644 index 0000000..1242c43 --- /dev/null +++ b/app/Services/UnsubscribeTokenService.php @@ -0,0 +1,51 @@ +tokenService = $tokenService; + $this->secret = $_ENV['UNSUBSCRIBE_SECRET'] ?? 'changeme'; + $this->ttl = 86400; // default: 24 hours + } + + /** + * Create an unsubscribe token. + * + * @param string $email + * @param int $timestamp + * @return string + */ + public function generate(string $email, int $timestamp): string + { + return $this->tokenService->generate($email . $timestamp, $this->secret); + } + + /** + * Validate an unsubscribe token. + * + * @param string $email + * @param int $timestamp + * @param string $token + * @return bool + */ + public function isValid(string $email, int $timestamp, string $token): bool + { + $data = $email . $timestamp; + return $this->tokenService->isValid($data, $token, $this->secret, $timestamp, $this->ttl); + } +} diff --git a/app/Utilities/UnsubscribeTokenHelper.php b/app/Utilities/UnsubscribeTokenHelper.php new file mode 100644 index 0000000..aea0f0d --- /dev/null +++ b/app/Utilities/UnsubscribeTokenHelper.php @@ -0,0 +1,45 @@ +
- + + + = $content ?> diff --git a/resources/views/layouts/header.php b/resources/views/layouts/header.php index 1422657..7532715 100644 --- a/resources/views/layouts/header.php +++ b/resources/views/layouts/header.php @@ -8,8 +8,10 @@ diff --git a/resources/views/pages/404.php b/resources/views/pages/404.php new file mode 100644 index 0000000..6d75e95 --- /dev/null +++ b/resources/views/pages/404.php @@ -0,0 +1,35 @@ + + +
+ The page you’re looking for doesn’t exist or may have been moved.
+ But hey, we’re Wizdom Networks — we can find anything. Almost.
+
+