forked from Gustavo/FrontFocusAgenda
b1dd3a8b01
meco meram, meco meram, meco meram
98 lines
3.4 KiB
HTML
98 lines
3.4 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="pt-br">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<link rel="icon" href="imagens/icone.png">
|
||
<link rel="stylesheet" href="login.css">
|
||
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
|
||
<title>Login – Focus Agenda</title>
|
||
</head>
|
||
<body>
|
||
<div id="topo">
|
||
<h1 id="textotop">Focus Agenda</h1>
|
||
</div>
|
||
|
||
<div id="log">
|
||
<h1 class="mens">Bem-vindo!</h1>
|
||
<h3 class="mens">Faça seu login</h3>
|
||
|
||
<div id="mensagem-erro" role="alert"></div>
|
||
|
||
<form id="loginForm" novalidate>
|
||
<div class="campo">
|
||
<label for="emailid">Email</label>
|
||
<input type="email" placeholder="Digite seu email" id="emailid" autocomplete="email" required>
|
||
</div>
|
||
<div class="campo">
|
||
<label for="senhaid">Senha</label>
|
||
<input type="password" placeholder="Digite sua senha" id="senhaid" autocomplete="current-password" required>
|
||
</div>
|
||
<button type="submit" id="logbtn">Entrar</button>
|
||
</form>
|
||
|
||
<p class="mens"><a href="cadastro.html">Cadastrar-se</a></p>
|
||
</div>
|
||
|
||
<script>
|
||
// Se já tiver token válido, redireciona direto
|
||
(function () {
|
||
if (localStorage.getItem('fa_token')) {
|
||
window.location.href = 'calendario.html';
|
||
}
|
||
})();
|
||
|
||
const form = document.getElementById('loginForm');
|
||
const erroEl = document.getElementById('mensagem-erro');
|
||
const btn = document.getElementById('logbtn');
|
||
|
||
function mostrarErro(msg) {
|
||
erroEl.textContent = msg;
|
||
erroEl.style.display = 'block';
|
||
}
|
||
|
||
form.addEventListener('submit', async (e) => {
|
||
e.preventDefault();
|
||
erroEl.style.display = 'none';
|
||
|
||
const email = document.getElementById('emailid').value.trim();
|
||
const senha = document.getElementById('senhaid').value;
|
||
|
||
if (!email || !senha) {
|
||
mostrarErro('Preencha todos os campos.');
|
||
return;
|
||
}
|
||
|
||
btn.disabled = true;
|
||
btn.textContent = 'Entrando...';
|
||
|
||
try {
|
||
const res = await fetch('/api/estudantes/login', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ email, senha })
|
||
});
|
||
|
||
const json = await res.json();
|
||
|
||
if (!res.ok) {
|
||
mostrarErro(json.message || 'Email ou senha incorretos.');
|
||
return;
|
||
}
|
||
|
||
// Salva token e dados do usuário
|
||
localStorage.setItem('fa_token', json.data.token);
|
||
localStorage.setItem('fa_user', JSON.stringify(json.data.estudante));
|
||
|
||
window.location.href = 'calendario.html';
|
||
} catch (err) {
|
||
mostrarErro('Erro de conexão. Verifique se o servidor está rodando.');
|
||
} finally {
|
||
btn.disabled = false;
|
||
btn.textContent = 'Entrar';
|
||
}
|
||
});
|
||
</script>
|
||
</body>
|
||
</html>
|