fix: preserva email no login quando senha incorreta
- Passa email como parametro na URL de erro - Preenche campo automaticamente ao recarregar - Foca no campo senha quando email ja preenchido Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -168,7 +168,13 @@
|
||||
el.textContent = 'E-mail ou senha incorretos.';
|
||||
el.style.display = 'block';
|
||||
}
|
||||
document.getElementById('email').focus();
|
||||
const emailParam = params.get('email');
|
||||
if (emailParam) {
|
||||
document.getElementById('email').value = emailParam;
|
||||
document.getElementById('senha').focus();
|
||||
} else {
|
||||
document.getElementById('email').focus();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -55,9 +55,10 @@ app.get('/login', (req, res) => {
|
||||
// Unified Login POST - detects role and redirects accordingly
|
||||
app.post('/login', async (req, res) => {
|
||||
const { email, senha } = req.body;
|
||||
const emailParam = encodeURIComponent(email || '');
|
||||
try {
|
||||
const user = await authenticate(email, senha);
|
||||
if (!user) return res.redirect('/login?error=1');
|
||||
if (!user) return res.redirect(`/login?error=1&email=${emailParam}`);
|
||||
|
||||
// Unified session
|
||||
req.session.user = {
|
||||
@@ -76,7 +77,7 @@ app.post('/login', async (req, res) => {
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Login error:', err);
|
||||
res.redirect('/login?error=1');
|
||||
res.redirect(`/login?error=1&email=${emailParam}`);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user