-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot_password.php
138 lines (131 loc) · 4.82 KB
/
forgot_password.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Forgot Password</title>
<link rel="stylesheet" href="assets/css/login.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap" rel="stylesheet">
<style>
.toast {
visibility: hidden;
min-width: 300px;
margin-left: -150px;
background-color: #d4edda;
color: #155724;
text-align: left;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1001;
left: 50%;
bottom: 30px;
font-size: 17px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
display: flex;
align-items: center;
}
.toast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, fadeout 0.5s 3.5s;
animation: fadein 0.5s, fadeout 0.5s 3.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 0; opacity: 0;}
}
.toast .icon {
margin-right: 10px;
font-size: 20px;
}
.toast .close {
margin-left: auto;
cursor: pointer;
}
/* Loading Spinner */
.spinner {
display: none;
width: 20px;
height: 20px;
border: 2px solid #fff;
border-top: 2px solid #6200ea;
border-radius: 50%;
animation: spin 0.5s linear infinite;
margin-left: 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<div class="form-container">
<h2>Forgot Password</h2>
<form id="forgot-password-form">
<label for="email">Enter your email address</label>
<input type="email" id="email" name="email" placeholder="[email protected]" required style="padding: 10px; border: none; border-radius: 5px; margin-bottom: 20px;">
<button type="submit" id="reset-button" style="padding: 10px; border: none; border-radius: 5px; background-color: #6200ea; color: #fff; font-size: 16px; cursor: pointer; font-family: Poppins, sans-serif;">
Send Reset Link
<span class="spinner" id="spinner"></span>
</button>
</form>
</div>
</div>
<!-- Toast Notification -->
<div id="toast" class="toast">
<span class="icon"><i class="fas fa-check-circle"></i></span>
<span class="message"></span>
<span class="close" onclick="hideToast()">×</span>
</div>
<script>
function showToast(message) {
var toast = document.getElementById("toast");
toast.querySelector(".message").innerText = message;
toast.className = "toast show";
setTimeout(function(){ hideToast(); }, 4000); // Show toast for 4 seconds
}
function hideToast() {
var toast = document.getElementById("toast");
toast.className = toast.className.replace("show", "");
}
document.getElementById('forgot-password-form').addEventListener('submit', function(event) {
event.preventDefault();
let email = document.getElementById('email').value;
let resetButton = document.getElementById('reset-button');
let spinner = document.getElementById('spinner');
// Show loading spinner and disable button
resetButton.disabled = true;
spinner.style.display = 'inline-block';
resetButton.style.cursor = 'not-allowed';
// AJAX request to send_reset_link.php
let xhr = new XMLHttpRequest();
xhr.open('POST', 'send_reset_link.php', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
showToast(xhr.responseText);
// Hide loading spinner and enable button
resetButton.disabled = false;
spinner.style.display = 'none';
resetButton.style.cursor = 'pointer';
}
};
xhr.send('email=' + encodeURIComponent(email));
});
</script>
</body>
</html>