Last active
December 26, 2015 18:19
-
-
Save return-none/7193683 to your computer and use it in GitHub Desktop.
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 by micah carrick | |
from django.contrib.auth.models import User, check_password | |
class EmailAuthBackend(object): | |
""" | |
Email Authentication Backend | |
Allows a user to sign in using an email/password pair rather than | |
a username/password pair. | |
""" | |
def authenticate(self, email=None, password=None): | |
""" Authenticate a user based on email address """ | |
try: | |
user = User.objects.get(email=email) | |
if user.check_password(password): | |
return user | |
else: | |
return None | |
except User.DoesNotExist: | |
return None | |
def get_user(self, user_id): | |
""" Get a User object from the user_id. """ | |
try: | |
return User.objects.get(pk=user_id) | |
except User.DoesNotExist: | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment