Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution to "Tell users if their account has been locked due to too many login attempts #1749" #1751

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions intranet/apps/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.urls import reverse
from django.utils import timezone
from django.utils.decorators import method_decorator
from django.utils.translation import gettext as _
from django.views.decorators.debug import sensitive_post_parameters
from django.views.generic.base import View

Expand Down Expand Up @@ -247,6 +248,11 @@ def post(self, request):

return response
else:
auth_errors = form.errors.get('__all__', [])
lockout_message = _("Your account has been locked due to too many failed login attempts. Please try again in a few minutes.")
for error in auth_errors:
if "locked" in error:
form.add_error(None, lockout_message)
log_auth(request, "failed")
logger.info("Login failed as %s", request.POST.get("username", "unknown"))
return index_view(request, auth_form=form)
Expand Down
10 changes: 10 additions & 0 deletions intranet/templates/auth/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ <h1>TJ Intranet</h1>
{{ auth_message }}
</div>
{% endif %}
{% if form.non_field_errors %}
<div class="alert alert-danger">
{% for error in form.non_field_errors %}
<p>{{ error }}</p>
{% endfor %}
</div>
{% endif %}
<form autocomplete="off" action="/login" method="post" name="auth_form">
{% if request.GET.next %}
<input type="hidden" name="next" value="{{ request.GET.next|escape }}">
Expand Down Expand Up @@ -116,6 +123,9 @@ <h1>TJ Intranet</h1>
<a href="{% url 'docs_accounts' %}">CSL Account Documentation</a>
</div>
{% endif %}
{% if lockout_message %}
<p class="error">{{ lockout_message }}</p>
{% endif %}
</form>
</div>
<div class="schedule-outer{% if sports_events|length > 0 or school_events|length > 0 %} has-events{% endif %}">
Expand Down
Loading