-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify-email.php
More file actions
141 lines (114 loc) · 4.85 KB
/
verify-email.php
File metadata and controls
141 lines (114 loc) · 4.85 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
session_start();
include "./assets/pages/_db.php";
$token = $_GET['token'] ?? '';
if (!$token) {
$_SESSION['msg'] = "Invalid or missing token.";
header("Location: signup.php");
exit;
}
// Validate token
$stmt = $conn->prepare("SELECT * FROM email_verification WHERE token = ?");
$stmt->bind_param("s", $token);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
$_SESSION['msg'] = "Token has expired or is invalid.";
header("Location: signup.php");
exit;
}
$userData = $result->fetch_assoc();
$email = $userData['email'];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Set Your Password - SmartResume</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body style="background-color: #ffffff;">
<?php include "./assets/pages/_header.php" ?>
<div id="liveAlertPlaceholder" class="position-fixed top-0 end-0 p-3" style="z-index: 9999;"></div>
<main>
<div class="container d-flex align-items-center justify-content-center" style="min-height: 70vh;">
<div class="card p-4 shadow"
style="width: 100%; max-width: 400px; border-radius: 1rem; background-color: #e3f2fd;">
<h2 class="text-center mb-4">Set Your Password</h2>
<!-- Password form -->
<form id="set-password-form" method="POST" action="process-password.php">
<input type="hidden" name="email" value="<?php echo htmlspecialchars($email); ?>">
<!-- New Password -->
<div class="mb-3">
<label for="password" class="form-label">New Password</label>
<input type="password" class="form-control" id="password" name="password" required
minlength="6">
</div>
<!-- Confirm Password -->
<div class="mb-3">
<label for="confirm_password" class="form-label">Confirm Password</label>
<input type="password" class="form-control" id="confirm_password" name="confirm_password"
required minlength="6">
</div>
<!-- Submit -->
<div class="d-grid">
<button type="submit" class="btn btn-dark">Set Password</button>
</div>
</form>
</div>
</div>
</main>
<?php include "./assets/pages/_footer.php" ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.5/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.getElementById('set-password-form').addEventListener('submit', function(e) {
e.preventDefault();
const pass = document.getElementById('password').value.trim();
const confirm = document.getElementById('confirm_password').value.trim();
const email = "<?php echo htmlspecialchars($email); ?>";
const strongPassRegex = /^(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).{8,}$/;
if (!strongPassRegex.test(pass)) {
showLiveAlert(
"Password must be at least 8 characters, include 1 uppercase, 1 number, and 1 special character.",
"warning");
return;
}
if (pass !== confirm) {
showLiveAlert("Passwords do not match!", "danger");
return;
}
// Submit via AJAX
const xhr = new XMLHttpRequest();
xhr.open("POST", "./assets/pages/api/_set_password.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onload = function() {
if (xhr.status === 200) {
if (xhr.responseText === "success") {
window.location.href = "login.php";
} else {
showLiveAlert("Something went wrong. Try again.", "danger");
}
console.log(xhr.responseText);
}
};
xhr.send(`email=${encodeURIComponent(email)}&password=${encodeURIComponent(pass)}`);
});
function showLiveAlert(message, type = "danger") {
const alertPlaceholder = document.getElementById("liveAlertPlaceholder");
const wrapper = document.createElement("div");
wrapper.innerHTML = `
<div class="alert alert-${type} alert-dismissible fade show" role="alert">
${message}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`;
alertPlaceholder.append(wrapper);
// Auto-dismiss after 4 seconds
setTimeout(() => {
const alert = bootstrap.Alert.getOrCreateInstance(wrapper.querySelector('.alert'));
alert.close();
}, 4000);
}
</script>
</body>
</html>