-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify_new_email.php
52 lines (44 loc) · 1.66 KB
/
verify_new_email.php
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
<?php
require 'config.php';
$message = '';
$messageClass = 'error';
if (isset($_GET['token'])) {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $db_username, $db_password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$token = $_GET['token'];
// Retrieve the user based on the verification token
$stmt = $pdo->prepare("SELECT id, new_email FROM users WHERE verification_token = ? AND new_email_verified = FALSE"
);
$stmt->execute([$token]);
$user = $stmt->fetch();
if ($user) {
// Update the user's email to the new email and clear the verification fields
$updateStmt = $pdo->prepare("UPDATE users SET email = ?, email_verified = TRUE, new_email = NULL, verification_
token = NULL, new_email_token = NULL, new_email_token_expiry = NULL WHERE id = ?");
$updateStmt->execute([$user['new_email'], $user['id']]);
$message = "Your new email address has been successfully verified. You may now log in. You will be redirected t
o the login page.";
$messageClass = 'success';
// Redirect to login page after 10 seconds
header("refresh:10;url=login.php");
} else {
$message = "This verification link is invalid or has expired.";
}
} else {
$message = "No verification token provided.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Email Verification</title>
<link rel="stylesheet" href="stylesheet.css">
</head>
<body>
<div class="verification-message <?php echo $messageClass; ?>">
<p><?php echo $message; ?></p>
</div>
</body>
</html>