-
-
Save langri-sha/721226 to your computer and use it in GitHub Desktop.
Django email auth backend via @rainerborene
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
#=============================================================================== | |
# Django email auth backend | |
#=============================================================================== | |
from django.contrib.auth.backends import ModelBackend | |
from django.contrib.auth.models import User | |
class EmailBackend(ModelBackend): | |
def authenticate(self, **credentials): | |
if not 'email' in credentials: | |
return super(EmailBackend, self).authenticate(**credentials) | |
try: | |
user = User.objects.get(email=credentials.get('email')) | |
if user.check_password(credentials.get('password')): | |
return user | |
except User.DoesNotExist: | |
return None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment