forked from pinax/pinax
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into wakawaka_integration
- Loading branch information
Showing
10 changed files
with
43 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,24 @@ | ||
from django.conf import settings | ||
|
||
from django.contrib.auth.backends import ModelBackend | ||
from django.contrib.auth.models import User | ||
|
||
|
||
|
||
class EmailModelBackend(ModelBackend): | ||
""" | ||
A backend that provides authentication through e-mail instead of username. | ||
""" | ||
class AuthenticationBackend(ModelBackend): | ||
|
||
def authenticate(self, email=None, password=None): | ||
def authenticate(self, **credentials): | ||
lookup_params = {} | ||
if settings.ACCOUNT_EMAIL_AUTHENTICATION: | ||
lookup_params["email"] = credentials["email"] | ||
else: | ||
lookup_params["username"] = credentials["username"] | ||
try: | ||
user = User.objects.get(email=email) | ||
if user.check_password(password): | ||
return user | ||
user = User.objects.get(**lookup_params) | ||
except User.DoesNotExist: | ||
return None | ||
else: | ||
if user.check_password(credentials["password"]): | ||
return user | ||
|
||
|
||
EmailModelBackend = AuthenticationBackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters