Files
Critters/verify-email.php
pauljd 9805d5056d
pauljd/davidson-ci: Davidson CI / quality (push) Successful in 14s
pauljd/davidson-ci: Davidson CI / ai-review (push) Successful in 1m5s
issues identified by Davidson CI
2026-09-09 22:49:46 +01:00

74 lines
3.8 KiB
PHP

<?php
require __DIR__ . '/session.php';
require __DIR__ . '/db.php';
require __DIR__ . '/lib/ticket.php';
start_app_session();
$token = $_GET['token'] ?? '';
$userId = is_string($token) && $token !== '' ? decodeTicket($token, 'email_verify') : null;
$status = 'invalid';
if ($userId !== null) {
$pdo = getDbConnection();
$stmt = $pdo->prepare('UPDATE users SET email_verified_at = CURRENT_TIMESTAMP, credits = credits + :credits WHERE id = :id AND email_verified_at IS NULL');
$stmt->execute(['credits' => STARTING_CREDITS, 'id' => $userId]);
if ($stmt->rowCount() === 1) {
$status = 'verified';
} else {
$checkStmt = $pdo->prepare('SELECT email_verified_at FROM users WHERE id = :id');
$checkStmt->execute(['id' => $userId]);
$existing = $checkStmt->fetchColumn();
$status = ($existing !== false && $existing !== null) ? 'already_verified' : 'invalid';
}
}
$pageTitle = 'Verify Email';
?>
<!DOCTYPE html>
<html lang="en">
<?php require __DIR__ . '/lib/head.php'; ?>
<body class="bg-amber-50 min-h-screen flex flex-col">
<?php require __DIR__ . '/lib/header.php'; ?>
<div class="flex-1 flex items-center justify-center bg-gradient-to-b from-amber-50 via-pink-50 to-white p-4 py-12">
<div class="w-full max-w-md bg-white rounded-3xl shadow-xl ring-1 ring-gray-100 p-8 sm:p-10 text-center">
<?php if ($status === 'verified'): ?>
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-green-50 text-green-500 mx-auto mb-4">
<i data-lucide="badge-check" class="h-7 w-7"></i>
</div>
<h1 class="text-2xl font-extrabold text-gray-900">Email verified!</h1>
<p class="mt-2 text-gray-500 text-sm">
Your email is confirmed and your free credits have been added to your account. You're ready to create.
</p>
<a href="/" class="mt-6 w-full inline-flex items-center justify-center gap-2 rounded-xl bg-gradient-to-r from-purple-600 to-pink-500 text-white font-semibold py-3 shadow-sm hover:from-purple-700 hover:to-pink-600">
Start Creating <i data-lucide="arrow-right" class="h-4 w-4"></i>
</a>
<?php elseif ($status === 'already_verified'): ?>
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-blue-50 text-blue-500 mx-auto mb-4">
<i data-lucide="badge-check" class="h-7 w-7"></i>
</div>
<h1 class="text-2xl font-extrabold text-gray-900">Already verified</h1>
<p class="mt-2 text-gray-500 text-sm">This email address has already been verified. You're all set.</p>
<a href="/" class="mt-6 w-full inline-flex items-center justify-center gap-2 rounded-xl bg-gray-900 text-white font-semibold py-3 hover:bg-gray-800">
Go Home <i data-lucide="arrow-right" class="h-4 w-4"></i>
</a>
<?php else: ?>
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-red-50 text-red-500 mx-auto mb-4">
<i data-lucide="shield-alert" class="h-7 w-7"></i>
</div>
<h1 class="text-2xl font-extrabold text-gray-900">Link expired</h1>
<p class="mt-2 text-gray-500 text-sm">
This verification link is invalid or has expired. You can request a new one from the create critter page.
</p>
<a href="/" class="mt-6 w-full inline-flex items-center justify-center gap-2 rounded-xl bg-gray-900 text-white font-semibold py-3 hover:bg-gray-800">
Go Home <i data-lucide="arrow-right" class="h-4 w-4"></i>
</a>
<?php endif; ?>
</div>
</div>
<?php require __DIR__ . '/lib/footer.php'; ?>
</body>
</html>