Skip to content

Commit

Permalink
Adds support for new Django 1.11 optional request argument on authent…
Browse files Browse the repository at this point in the history
…icate().
  • Loading branch information
pbaehr committed May 2, 2017
1 parent 3911018 commit 890cea3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -10,6 +10,7 @@ Contributors
* Bryan Kaplan
* Ming Chen
* Adilet Maratov
* Peter Baehr


If you have contributed to MamaCAS in any substantial way, such as adding
Expand Down
2 changes: 1 addition & 1 deletion mama_cas/forms.py
Expand Up @@ -39,7 +39,7 @@ def clean(self):

if username and password:
try:
self.user = authenticate(self.request, username=username, password=password)
self.user = authenticate(request=self.request, username=username, password=password)
except Exception:
logger.exception("Error authenticating %s" % username)
error_msg = _('Internal error while authenticating user')
Expand Down
4 changes: 2 additions & 2 deletions mama_cas/tests/backends.py
Expand Up @@ -4,13 +4,13 @@

class ExceptionBackend(ModelBackend):
"""Raise an exception on authentication for testing purposes."""
def authenticate(self, username=None, password=None):
def authenticate(self, request, username=None, password=None):
raise Exception


class CaseInsensitiveBackend(ModelBackend):
"""A case-insenstitive authentication backend."""
def authenticate(self, username=None, password=None):
def authenticate(self, request, username=None, password=None):
user_model = get_user_model()
try:
user = user_model.objects.get(username__iexact=username)
Expand Down
8 changes: 8 additions & 0 deletions mama_cas/views.py
Expand Up @@ -56,6 +56,14 @@ class LoginView(CsrfProtectMixin, NeverCacheMixin, FormView):
form_class = LoginForm

def get_form_kwargs(self):
"""
Django >= 1.11 supports a request sent to the authenticator
so we grab that here and pass it along to the form so it can be
handed off to the authenticators.
"""
"""
:return:
"""
kwargs = super(LoginView, self).get_form_kwargs()
kwargs['request'] = self.request
return kwargs
Expand Down

0 comments on commit 890cea3

Please sign in to comment.