Initial commit: Portugais App
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
|
||||
<meta name="theme-color" content="#006600">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<title>Connexion - Portugais pour Tous</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body class="auth-page">
|
||||
<div class="auth-container">
|
||||
<div class="auth-card">
|
||||
<div class="auth-flag">🇵🇹</div>
|
||||
<h1>Portugais pour Tous</h1>
|
||||
<p class="auth-subtitle">Connecte-toi pour apprendre !</p>
|
||||
|
||||
<form id="login-form" class="auth-form">
|
||||
<div class="form-group">
|
||||
<label for="login-username">Nom d'utilisateur</label>
|
||||
<input type="text" id="login-username" placeholder="Ton prénom..." autocomplete="username" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="login-password">Mot de passe</label>
|
||||
<input type="password" id="login-password" placeholder="Mot de passe..." autocomplete="current-password" required>
|
||||
</div>
|
||||
<div id="login-error" class="form-error hidden"></div>
|
||||
<button type="submit" class="auth-btn">
|
||||
<span>Se connecter</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="auth-footer">
|
||||
<p>Apprends le portugais en t'amusant !</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
if (localStorage.getItem('pt_token')) {
|
||||
window.location.href = '/';
|
||||
}
|
||||
|
||||
document.getElementById('login-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const errorEl = document.getElementById('login-error');
|
||||
errorEl.classList.add('hidden');
|
||||
|
||||
const username = document.getElementById('login-username').value.trim();
|
||||
const password = document.getElementById('login-password').value;
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username, password })
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error);
|
||||
|
||||
localStorage.setItem('pt_token', data.token);
|
||||
localStorage.setItem('pt_user', JSON.stringify(data.user));
|
||||
window.location.href = '/';
|
||||
} catch (err) {
|
||||
errorEl.textContent = err.message;
|
||||
errorEl.classList.remove('hidden');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user