-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreset-password.html
More file actions
352 lines (304 loc) · 11.5 KB
/
reset-password.html
File metadata and controls
352 lines (304 loc) · 11.5 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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Reset Password - LiteNotes</title>
<meta name="robots" content="noindex">
<!-- <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"> -->
<link rel="icon" href="images/blue_icon.png" type="image/png">
<!-- Preload critical fonts -->
<link rel="preload" href="/src/fonts/inter-v18-latin/inter-v18-latin-regular.woff2" as="font" type="font/woff2"
crossorigin>
<link rel="preload" href="/src/fontawesome/webfonts/fa-solid-900.woff2" as="font" type="font/woff2" crossorigin>
<!-- Use local FontAwesome (Loaded Asynchronously) -->
<link rel="stylesheet" href="/fontawesome/css/all.min.css" media="print" onload="this.media='all'">
<noscript>
<link rel="stylesheet" href="/fontawesome/css/all.min.css">
</noscript>
<!-- Use src path for styles -->
<link rel="stylesheet" href="/src/styles.css">
<style>
/* Add some basic styles similar to the login/register modal */
:root {
/* Dark theme (default) */
--bg-primary: #0f0f0f;
--bg-secondary: #1a1a1a;
--text-primary: #ffffff;
--text-secondary: #a0a0a0;
--border: #2a2a2a;
--hover: #2a2a2a;
--danger: #ffffff;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
--radius: 8px;
}
/* Light theme */
.light-mode {
--bg-primary: #ffffff;
--bg-secondary: #f5f5f5;
--text-primary: #0f0f0f;
--text-secondary: #555555;
--border: #e0e0e0;
--hover: #f0f0f0;
--danger: #0f0f0f;
--shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
body {
background-color: var(--bg-primary);
color: var(--text-primary);
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
transition: background-color 0.2s ease, color 0.2s ease;
}
.reset-box {
width: 360px;
background-color: var(--bg-secondary);
border-radius: 16px;
padding: 2.5rem;
box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
border: 1px solid var(--border);
animation: fadeIn 0.5s ease-out;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.auth-header {
text-align: center;
margin-bottom: 2rem;
}
.auth-header h1 {
font-size: 2rem;
font-weight: 700;
margin-bottom: 0.5rem;
color: var(--text-primary);
}
.form-group {
margin-bottom: 1.5rem;
}
.form-label {
display: block;
margin-bottom: 0.5rem;
font-size: 0.9rem;
color: var(--text-secondary);
font-weight: 500;
}
.form-input {
width: 100%;
padding: 12px;
background-color: var(--bg-primary);
border: 1px solid var(--border);
border-radius: var(--radius);
color: var(--text-primary);
font-size: 1rem;
transition: all 0.2s;
}
.form-input:focus {
outline: none;
border-color: var(--text-primary);
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}
.btn {
display: block;
width: 100%;
padding: 12px;
border: none;
border-radius: var(--radius);
font-size: 1rem;
font-weight: 600;
cursor: pointer;
background-color: var(--text-primary);
color: var(--bg-primary);
transition: all 0.2s;
}
.btn:hover {
background-color: #f0f0f0;
transform: translateY(-2px);
}
.btn:active {
transform: translateY(1px);
background-color: #e0e0e0;
}
.message {
margin-top: 1rem;
text-align: center;
font-size: 0.9rem;
}
.message.success {
color: var(--text-primary);
border-left: 4px solid var(--text-primary);
padding-left: 10px;
}
.message.error {
color: var(--text-primary);
border-left: 4px solid var(--text-primary);
padding-left: 10px;
}
a {
color: var(--text-primary);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Theme toggle */
.theme-toggle {
position: fixed;
top: 20px;
right: 20px;
background: var(--bg-secondary);
width: 36px;
height: 36px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
z-index: 10;
transition: all 0.3s;
border: 1px solid var(--border);
}
.theme-toggle i {
font-size: 16px;
color: var(--text-primary);
transition: transform 0.3s;
}
.theme-toggle:hover {
transform: translateY(-2px);
}
</style>
</head>
<body>
<div class="reset-box">
<div class="auth-header">
<h1>Set New Password</h1>
</div>
<div id="reset-form">
<div class="form-group">
<label for="new-password" class="form-label">New Password (min. 7 characters)</label>
<input type="password" id="new-password" class="form-input" placeholder="Enter new password">
</div>
<div class="form-group">
<label for="confirm-password" class="form-label">Confirm New Password</label>
<input type="password" id="confirm-password" class="form-input" placeholder="Confirm new password">
</div>
<button id="reset-button" class="btn">Reset Password</button>
<div id="message-area" class="message"></div>
</div>
</div>
<div class="theme-toggle" id="theme-toggle">
<i class="fas fa-sun"></i>
</div>
<script>
const newPasswordInput = document.getElementById('new-password');
const confirmPasswordInput = document.getElementById('confirm-password');
const resetButton = document.getElementById('reset-button');
const messageArea = document.getElementById('message-area');
const themeToggle = document.getElementById('theme-toggle');
let isDarkMode = true; // Default to dark mode
// Get token from URL query parameters - MANUAL PARSING
let resetToken = null;
const query = window.location.search;
const tokenPrefix = '?token_';
if (query.startsWith(tokenPrefix)) {
resetToken = query.substring(tokenPrefix.length);
// Optional: Decode if needed (though hex token shouldn't need it)
// resetToken = decodeURIComponent(resetToken);
}
if (!resetToken) {
messageArea.textContent = 'Error: No valid reset token found in URL.';
messageArea.className = 'message error';
resetButton.disabled = true;
}
// Theme toggle functionality
themeToggle.addEventListener('click', toggleTheme);
// Check for saved theme preference when page loads
document.addEventListener('DOMContentLoaded', () => {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
isDarkMode = false;
document.body.classList.add('light-mode');
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
}
});
// Toggle theme function
function toggleTheme() {
isDarkMode = !isDarkMode;
if (isDarkMode) {
document.body.classList.remove('light-mode');
themeToggle.innerHTML = '<i class="fas fa-sun"></i>';
localStorage.setItem('theme', 'dark');
} else {
document.body.classList.add('light-mode');
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
localStorage.setItem('theme', 'light');
}
}
resetButton.addEventListener('click', async () => {
const newPassword = newPasswordInput.value;
const confirmPassword = confirmPasswordInput.value;
messageArea.textContent = ''; // Clear previous messages
if (!newPassword || newPassword.length < 7) {
messageArea.textContent = 'Password must be at least 7 characters long.';
messageArea.className = 'message error';
return;
}
if (newPassword !== confirmPassword) {
messageArea.textContent = 'Passwords do not match.';
messageArea.className = 'message error';
return;
}
if (!resetToken) {
messageArea.textContent = 'Error: Missing reset token.';
messageArea.className = 'message error';
return;
}
try {
resetButton.disabled = true;
resetButton.textContent = 'Resetting...';
const response = await fetch('/reset-password', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ token: resetToken, newPassword: newPassword })
});
const data = await response.json();
if (!response.ok) {
throw new Error(data.message || 'Failed to reset password');
}
messageArea.textContent = data.message + ' You can now log in with your new password.';
messageArea.className = 'message success';
// Optionally disable form fields after success
newPasswordInput.disabled = true;
confirmPasswordInput.disabled = true;
// Add a link back to the main login page
const loginLink = document.createElement('p');
loginLink.innerHTML = '<a href="/">Go to Login</a>';
messageArea.appendChild(loginLink);
} catch (error) {
messageArea.textContent = error.message || 'An error occurred. Please try again.';
messageArea.className = 'message error';
resetButton.disabled = false;
resetButton.textContent = 'Reset Password';
}
});
// Apply saved theme on page load
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
isDarkMode = false;
document.body.classList.add('light-mode');
themeToggle.innerHTML = '<i class="fas fa-moon"></i>';
}
</script>
</body>
</html>