Guest User

Untitled

a guest
Apr 9th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. error_messages = {
  2. 'invalid_login': _(
  3. "Please enter a correct %(username)s and password. Note that both "
  4. "fields may be case-sensitive."
  5. ),
  6. 'inactive': _("This account is inactive."),
  7.  
  8. def clean(self):
  9. username = self.cleaned_data.get('username')
  10. password = self.cleaned_data.get('password')
  11.  
  12. if username is not None and password:
  13. self.user_cache = authenticate(self.request, username=username, password=password)
  14. if self.user_cache is None:
  15. raise self.get_invalid_login_error()
  16. else:
  17. self.confirm_login_allowed(self.user_cache)
  18.  
  19. return self.cleaned_data
  20.  
  21.  
  22. def get_invalid_login_error(self):
  23. return forms.ValidationError(
  24. self.error_messages['invalid_login'],
  25. code='invalid_login',
  26. params={'username': self.username_field.verbose_name},
  27. )
Add Comment
Please, Sign In to add comment