feat: Implement password reset and change functionality

Co-authored-by: mathieumoran1 <[email protected]>
This commit is contained in:
Cursor Agent
2025-12-20 23:13:51 +00:00
co-authored by mathieumoran1
parent 7a5ef7e9a0
commit c83b4685a2
11 changed files with 386 additions and 18 deletions
+19 -3
View File
@@ -1,8 +1,24 @@
function decodeJwt(token) {
return JSON.parse(atob(token.split('.')[1]));
}
// Check if the user is already logged in by looking for auth_token in localStorage
if (localStorage.getItem('auth_token')) {
// If the token is found, redirect to /movies.html
window.location.href = '/movies.html';
const existingToken = localStorage.getItem('auth_token');
if (existingToken) {
try {
const decoded = decodeJwt(existingToken);
const currentTime = Math.floor(Date.now() / 1000);
if (decoded.exp && decoded.exp < currentTime) {
localStorage.removeItem('auth_token');
} else if (decoded.mustChangePassword) {
window.location.href = '/change-password.html';
} else {
window.location.href = '/movies.html';
}
} catch (_) {
localStorage.removeItem('auth_token');
}
}
// Handle registration form submission
document.getElementById('register-form').addEventListener('submit', async function (e) {