Created
November 28, 2011 17:42
-
-
Save juanriaza/1401251 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
from django.core.validators import email_re | |
from django.contrib.auth.backends import ModelBackend | |
from django.contrib.auth.models import User | |
class YaraAuthenticationBackend(ModelBackend): | |
def authenticate(self, identification, password=None): | |
try: | |
if email_re.search(identification): | |
user = User.objects.get(email__iexact=identification) | |
else: | |
user = User.objects.get(username__iexact=identification) | |
if user.check_password(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