better login error style

This commit is contained in:
Gamosoft 2025-11-15 13:05:48 +01:00
parent 7b01123159
commit 1e09709c1f
2 changed files with 60 additions and 19 deletions

View File

@ -164,8 +164,12 @@ async def login_page(request: Request, error: str = None):
# Inject error message if present # Inject error message if present
if error: if error:
content = content.replace('<!-- ERROR_PLACEHOLDER -->', content = content.replace('<!-- ERROR_CLASS_PLACEHOLDER -->', 'class="error"')
f'<div class="error-message">❌ {error}</div>') content = content.replace('<!-- ERROR_MESSAGE_PLACEHOLDER -->',
f'<div class="error-message">{error}</div>')
else:
content = content.replace('<!-- ERROR_CLASS_PLACEHOLDER -->', '')
content = content.replace('<!-- ERROR_MESSAGE_PLACEHOLDER -->', '')
return content return content
@ -183,7 +187,7 @@ async def login(request: Request, password: str = Form(...)):
return RedirectResponse(url="/", status_code=303) return RedirectResponse(url="/", status_code=303)
else: else:
# Redirect back to login with error message # Redirect back to login with error message
return RedirectResponse(url="/login?error=Invalid+password.+Please+try+again.", status_code=303) return RedirectResponse(url="/login?error=Incorrect+password.+Please+try+again.", status_code=303)
@app.get("/logout") @app.get("/logout")

View File

@ -84,6 +84,11 @@
gap: 1rem; gap: 1rem;
} }
form > div {
display: flex;
flex-direction: column;
}
input[type="password"] { input[type="password"] {
width: 100%; width: 100%;
padding: 0.875rem 1rem; padding: 0.875rem 1rem;
@ -125,14 +130,43 @@
} }
.error-message { .error-message {
background-color: #fee; color: var(--error, #c53030);
color: #c53030; font-size: 0.813rem;
padding: 0.875rem 1rem; margin-top: 0.5rem;
border-radius: 8px;
font-size: 0.875rem;
margin-bottom: 1rem;
border: 1px solid #fcc;
text-align: left; text-align: left;
display: flex;
align-items: center;
gap: 0.375rem;
animation: fadeInDown 0.3s ease-out;
}
.error-message::before {
content: "⚠️";
flex-shrink: 0;
font-size: 0.875rem;
}
/* Shake animation for password input on error */
input.error {
animation: shake 0.4s ease-in-out;
border-color: var(--error, #c53030);
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
20%, 40%, 60%, 80% { transform: translateX(8px); }
}
@keyframes fadeInDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
} }
.footer { .footer {
@ -159,16 +193,19 @@
<h1>NoteDiscovery</h1> <h1>NoteDiscovery</h1>
<p class="tagline">Your Self-Hosted Knowledge Base</p> <p class="tagline">Your Self-Hosted Knowledge Base</p>
<!-- ERROR_PLACEHOLDER -->
<form method="post" action="/login"> <form method="post" action="/login">
<div>
<input <input
type="password" type="password"
name="password" name="password"
id="password"
placeholder="Enter your password" placeholder="Enter your password"
required required
autofocus autofocus
<!-- ERROR_CLASS_PLACEHOLDER -->
> >
<!-- ERROR_MESSAGE_PLACEHOLDER -->
</div>
<button type="submit">🔓 Unlock</button> <button type="submit">🔓 Unlock</button>
</form> </form>