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.textContent = 'E-mail ou senha incorretos.';
|
||||||
el.style.display = 'block';
|
el.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
const emailParam = params.get('email');
|
||||||
|
if (emailParam) {
|
||||||
|
document.getElementById('email').value = emailParam;
|
||||||
|
document.getElementById('senha').focus();
|
||||||
|
} else {
|
||||||
document.getElementById('email').focus();
|
document.getElementById('email').focus();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -55,9 +55,10 @@ app.get('/login', (req, res) => {
|
|||||||
// Unified Login POST - detects role and redirects accordingly
|
// Unified Login POST - detects role and redirects accordingly
|
||||||
app.post('/login', async (req, res) => {
|
app.post('/login', async (req, res) => {
|
||||||
const { email, senha } = req.body;
|
const { email, senha } = req.body;
|
||||||
|
const emailParam = encodeURIComponent(email || '');
|
||||||
try {
|
try {
|
||||||
const user = await authenticate(email, senha);
|
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
|
// Unified session
|
||||||
req.session.user = {
|
req.session.user = {
|
||||||
@@ -76,7 +77,7 @@ app.post('/login', async (req, res) => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Login error:', 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