70 lines
2.5 KiB
HTML
70 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Pool Oscar 2025</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
|
<link rel="manifest" href="/site.webmanifest">
|
|
</head>
|
|
<body class="bg-light">
|
|
|
|
<div class="container d-flex justify-content-center align-items-center vh-100">
|
|
<div class="card p-4" style="max-width: 400px;">
|
|
<div class="text-center mb-4">
|
|
<img src="img/logo.png" style="width: 80%";>
|
|
</div>
|
|
<form id="login-form">
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Courriel</label>
|
|
<input type="email" class="form-control" id="email" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="password" class="form-label">Mot de passe</label>
|
|
<input type="password" class="form-control" id="password" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">Connexion</button>
|
|
</form>
|
|
<p class="mt-3 text-center">Pas de compte? <a href="/register.html">Enregistrez-vous</a></p>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
// 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';
|
|
}
|
|
|
|
// Handle login form submission
|
|
document.getElementById('login-form').addEventListener('submit', async function (e) {
|
|
e.preventDefault();
|
|
|
|
const email = document.getElementById('email').value;
|
|
const password = document.getElementById('password').value;
|
|
|
|
const res = await fetch('/api/users/login', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ email, password })
|
|
});
|
|
|
|
if (res.ok) {
|
|
const data = await res.json();
|
|
// Save the token to localStorage
|
|
localStorage.setItem('auth_token', data.token);
|
|
window.location.href = '/movies.html'; // Redirect to movies page on success
|
|
} else {
|
|
const error = await res.json();
|
|
alert(`Login failed: ${error.message}`);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|