website: fix login banner showing before any attempt (fixes #3810)

The login page template currently displays the red
"Your username and password are incorrect. Please try again."
banner whenever `form.errors` is truthy. This includes the
initial GET request, so the error is visible before any
credentials have been submitted.

This patch gates the banner on
`form.is_bound and form.non_field_errors`, which matches
Django's intended semantics:

- GET (unbound form) → no banner
- POST with bad credentials (non_field_errors) → banner shown
- POST with valid credentials → no banner

The original banner text is preserved verbatim.
This commit is contained in:
Userland Alchemist 2025-08-20 22:06:51 +01:00
parent 27f0ccec4a
commit 5dd5f07898

View File

@ -16,7 +16,7 @@
{% if user.is_authenticated %}
<div class="alert alert-info" role="alert">You are already logged in!</div>
{% else %}
{% if form.errors %}
{% if form.is_bound and form.non_field_errors %}
<div class="alert alert-danger" role="alert">Your username and password are incorrect. Please try again.</div>
{% endif %}
{% endif %}