96 lines
3.5 KiB
PHP
96 lines
3.5 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// If user doesn't need to verify, redirect away
|
|
if (!isset($_SESSION['user_id_to_verify'])) {
|
|
header('Location: register.php');
|
|
exit;
|
|
}
|
|
|
|
$error_message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$verification_code = $_POST['verification_code'] ?? '';
|
|
|
|
if (empty($verification_code)) {
|
|
$error_message = 'Please enter the verification code.';
|
|
} else {
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?');
|
|
$stmt->execute([$_SESSION['user_id_to_verify']]);
|
|
$user = $stmt->fetch();
|
|
|
|
if ($user && $user['two_factor_secret'] === $verification_code) {
|
|
// Mark phone as verified
|
|
$stmt = $pdo->prepare('UPDATE users SET phone_verified_at = NOW(), two_factor_secret = NULL WHERE id = ?');
|
|
$stmt->execute([$_SESSION['user_id_to_verify']]);
|
|
|
|
unset($_SESSION['user_id_to_verify']);
|
|
$_SESSION['flash_message'] = 'Phone number verified successfully! You can now log in.';
|
|
header('Location: login.php');
|
|
exit;
|
|
} else {
|
|
$error_message = 'Invalid verification code. Please try again.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$error_message = 'Database error. Please try again later.';
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Verify Phone Number - AI Recipe Generator</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Navbar -->
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white fixed-top">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">AI Recipe Generator</a>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Content -->
|
|
<main>
|
|
<div class="container py-5">
|
|
<div class="auth-container">
|
|
<h2 class="text-center">Verify Your Phone</h2>
|
|
<p class="text-center text-muted mb-4">A verification code has been sent to your mobile number. Please enter it below.</p>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<form action="verify_phone.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="verification_code" class="form-label">Verification Code</label>
|
|
<input type="text" class="form-control" id="verification_code" name="verification_code" required autofocus>
|
|
</div>
|
|
<div class="d-grid">
|
|
<button type="submit" class="btn btn-primary">Verify & Continue</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Footer -->
|
|
<footer class="footer">
|
|
<div class="container text-center">
|
|
<p>© <?php echo date("Y"); ?> AI Recipe Generator. All Rights Reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|