-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_email.php
More file actions
93 lines (86 loc) · 3.25 KB
/
verify_email.php
File metadata and controls
93 lines (86 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
require_once 'db_con.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Email Verification - Libmanan Food</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="https://cdn.tailwindcss.com/3.4.16"></script>
<link rel='stylesheet' href='vendors/css/theme-toggle.css'/>
</head>
<body class="bg-gray-50 flex items-center justify-center min-h-screen">
<?php
if (isset($_GET['code'])) {
$code = $_GET['code'];
// Check for the verification code in the database
$stmt = $conn->prepare("SELECT user_id FROM accounts WHERE verification_code = ? AND email_verified = 0");
$stmt->bind_param("s", $code);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 1) {
// Verification Successful
$update = $conn->prepare("UPDATE accounts SET email_verified = 1, verification_code = NULL WHERE verification_code = ?");
$update->bind_param("s", $code);
if ($update->execute()) {
echo "
<script>
document.addEventListener('DOMContentLoaded', function() {
Swal.fire({
icon: 'success',
title: 'Email Verified!',
text: 'Your email has been successfully verified. You may now log in.',
confirmButtonText: 'Go to Login',
confirmButtonColor: '#A80000', // Your primary brand color
allowOutsideClick: false
}).then((result) => {
if (result.isConfirmed) {
window.location.href = 'index.php'; // Redirect to index
}
});
});
</script>";
} else {
// Database update failed
echo "
<script>
document.addEventListener('DOMContentLoaded', function() {
Swal.fire({
icon: 'error',
title: 'System Error',
text: 'Something went wrong while updating your account. Please try again.',
confirmButtonColor: '#A80000'
}).then(() => {
window.location.href = 'index.php';
});
});
</script>";
}
} else {
// Invalid or Expired Code
echo "
<script>
document.addEventListener('DOMContentLoaded', function() {
Swal.fire({
icon: 'error',
title: 'Invalid Link',
text: 'This verification link is invalid, expired, or the account is already verified.',
confirmButtonText: 'Back to Home',
confirmButtonColor: '#A80000'
}).then(() => {
window.location.href = 'index.php';
});
});
</script>";
}
} else {
// No code provided, direct redirect
header("Location: index.php");
exit();
}
?>
<script src='vendors/js/theme-toggle.js'></script>
</body>
</html>