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

provide context for invalid_login in admin form #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 7 additions & 5 deletions ratelimitbackend/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ class AdminAuthenticationForm(AdminAuthForm):
def clean(self):
username = self.cleaned_data.get('username')
password = self.cleaned_data.get('password')
message = self.error_messages['invalid_login']

if username and password:
self.user_cache = authenticate(username=username,
password=password,
request=self.request)
if self.user_cache is None:
raise forms.ValidationError(message)
elif not self.user_cache.is_active or not self.user_cache.is_staff:
raise forms.ValidationError(message)
if (self.user_cache is None or not self.user_cache.is_active
or not self.user_cache.is_staff):
raise forms.ValidationError(
self.error_messages['invalid_login'],
code='invalid_login',
params={'username': self.username_field.verbose_name}
)
return self.cleaned_data