-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreset-password.html
More file actions
293 lines (272 loc) · 10.8 KB
/
reset-password.html
File metadata and controls
293 lines (272 loc) · 10.8 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password - Sneakers</title>
<link rel="stylesheet" href="/styles/main.css">
<style>
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}
.reset-container {
background: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 10px 40px rgba(0,0,0,0.1);
width: 100%;
max-width: 400px;
}
h1 {
color: #333;
margin-bottom: 1.5rem;
text-align: center;
}
.form-group {
margin-bottom: 1rem;
}
label {
display: block;
margin-bottom: 0.5rem;
color: #555;
font-weight: 500;
}
input {
width: 100%;
padding: 0.75rem;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 1rem;
transition: border-color 0.3s;
}
input:focus {
outline: none;
border-color: #667eea;
}
button {
width: 100%;
padding: 0.75rem;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
border-radius: 5px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s;
}
button:hover {
transform: translateY(-2px);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.alert {
padding: 0.75rem;
border-radius: 5px;
margin-bottom: 1rem;
text-align: center;
}
.alert-success {
background: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.alert-error {
background: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.alert-info {
background: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
.password-requirements {
font-size: 0.85rem;
color: #666;
margin-top: 0.5rem;
}
.requirement {
margin: 0.25rem 0;
}
.requirement.met {
color: #28a745;
}
.requirement.met::before {
content: "✓ ";
}
.requirement:not(.met)::before {
content: "○ ";
}
.back-link {
text-align: center;
margin-top: 1rem;
}
.back-link a {
color: #667eea;
text-decoration: none;
}
</style>
</head>
<body>
<div class="reset-container">
<!-- Request Reset Form -->
<div id="requestForm">
<h1>Reset Password</h1>
<div id="requestAlert"></div>
<form id="resetRequestForm">
<div class="form-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" required placeholder="Enter your email">
</div>
<button type="submit" id="requestBtn">Send Reset Link</button>
</form>
<div class="back-link">
<a href="/">Back to Login</a>
</div>
</div>
<!-- Update Password Form (shown when token present) -->
<div id="updateForm" style="display: none;">
<h1>Set New Password</h1>
<div id="updateAlert"></div>
<form id="passwordUpdateForm">
<div class="form-group">
<label for="newPassword">New Password</label>
<input type="password" id="newPassword" name="newPassword" required>
<div class="password-requirements">
<div class="requirement" id="req-length">At least 8 characters</div>
<div class="requirement" id="req-upper">One uppercase letter</div>
<div class="requirement" id="req-lower">One lowercase letter</div>
<div class="requirement" id="req-number">One number</div>
<div class="requirement" id="req-special">One special character (!@#$%^&*)</div>
</div>
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" required>
</div>
<button type="submit" id="updateBtn">Update Password</button>
</form>
<div class="back-link">
<a href="/">Back to Login</a>
</div>
</div>
</div>
<script>
// Check if we have a reset token in URL
const urlParams = new URLSearchParams(window.location.search);
const resetToken = urlParams.get('token');
if (resetToken) {
// Show update form
document.getElementById('requestForm').style.display = 'none';
document.getElementById('updateForm').style.display = 'block';
}
// Password strength checker
const passwordInput = document.getElementById('newPassword');
if (passwordInput) {
passwordInput.addEventListener('input', function() {
const password = this.value;
// Check requirements
document.getElementById('req-length').classList.toggle('met', password.length >= 8);
document.getElementById('req-upper').classList.toggle('met', /[A-Z]/.test(password));
document.getElementById('req-lower').classList.toggle('met', /[a-z]/.test(password));
document.getElementById('req-number').classList.toggle('met', /[0-9]/.test(password));
document.getElementById('req-special').classList.toggle('met', /[!@#$%^&*]/.test(password));
});
}
// Request reset form handler
document.getElementById('resetRequestForm').addEventListener('submit', async function(e) {
e.preventDefault();
const email = document.getElementById('email').value;
const btn = document.getElementById('requestBtn');
const alertDiv = document.getElementById('requestAlert');
btn.disabled = true;
btn.textContent = 'Sending...';
try {
const response = await fetch('/api/auth/reset-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ email })
});
const data = await response.json();
if (response.ok) {
alertDiv.className = 'alert alert-success';
alertDiv.textContent = 'If an account exists with this email, a reset link has been sent.';
this.reset();
} else {
alertDiv.className = 'alert alert-error';
alertDiv.textContent = data.error || 'Failed to send reset email';
}
} catch (error) {
alertDiv.className = 'alert alert-error';
alertDiv.textContent = 'Network error. Please try again.';
}
btn.disabled = false;
btn.textContent = 'Send Reset Link';
});
// Update password form handler
document.getElementById('passwordUpdateForm')?.addEventListener('submit', async function(e) {
e.preventDefault();
const newPassword = document.getElementById('newPassword').value;
const confirmPassword = document.getElementById('confirmPassword').value;
const btn = document.getElementById('updateBtn');
const alertDiv = document.getElementById('updateAlert');
if (newPassword !== confirmPassword) {
alertDiv.className = 'alert alert-error';
alertDiv.textContent = 'Passwords do not match';
return;
}
btn.disabled = true;
btn.textContent = 'Updating...';
try {
const response = await fetch('/api/auth/update-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: resetToken,
newPassword
})
});
const data = await response.json();
if (response.ok) {
alertDiv.className = 'alert alert-success';
alertDiv.textContent = 'Password updated successfully! Redirecting to login...';
this.reset();
// Show instructions if provided (dev mode)
if (data.instructions) {
alertDiv.innerHTML += '<div class="alert alert-info" style="margin-top: 1rem; text-align: left;">' +
'<strong>Manual Update Required:</strong><br>' +
data.instructions.step1 + '<br>' +
data.instructions.step2 + '<br>' +
'<code style="word-break: break-all;">' + data.instructions.newHash + '</code>' +
'</div>';
} else {
setTimeout(() => {
window.location.href = '/';
}, 3000);
}
} else {
alertDiv.className = 'alert alert-error';
alertDiv.textContent = data.error || 'Failed to update password';
}
} catch (error) {
alertDiv.className = 'alert alert-error';
alertDiv.textContent = 'Network error. Please try again.';
}
btn.disabled = false;
btn.textContent = 'Update Password';
});
</script>
</body>
</html>