Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow use with auth backends that don't require username/password #66

Merged
merged 2 commits into from

2 participants

@justinabrahms

Previously, this would throw a KeyError which prevented this to be used in conjunction with an auth backend I'm writing which accepts only a token key.

@brosner brosner merged commit 4a02cd9 into pinax:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2013
  1. @justinabrahms
Commits on Mar 26, 2013
  1. @justinabrahms
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 7 deletions.
  1. +12 −7 account/auth_backends.py
View
19 account/auth_backends.py
@@ -11,12 +11,14 @@ class UsernameAuthenticationBackend(ModelBackend):
def authenticate(self, **credentials):
try:
user = User.objects.get(username__iexact=credentials["username"])
- except User.DoesNotExist:
+ except (User.DoesNotExist, KeyError):
return None
else:
- if user.check_password(credentials["password"]):
- return user
-
+ try:
+ if user.check_password(credentials["password"]):
+ return user
+ except KeyError:
+ return None
class EmailAuthenticationBackend(ModelBackend):
@@ -24,9 +26,12 @@ def authenticate(self, **credentials):
qs = EmailAddress.objects.filter(Q(primary=True) | Q(verified=True))
try:
email_address = qs.get(email__iexact=credentials["username"])
- except EmailAddress.DoesNotExist:
+ except (EmailAddress.DoesNotExist, KeyError):
return None
else:
user = email_address.user
- if user.check_password(credentials["password"]):
- return user
+ try:
+ if user.check_password(credentials["password"]):
+ return user
+ except KeyError:
+ return None
Something went wrong with that request. Please try again.