Skip to content

Instantly share code, notes, and snippets.

@leah
Created November 7, 2009 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leah/228806 to your computer and use it in GitHub Desktop.
Save leah/228806 to your computer and use it in GitHub Desktop.
from django.contrib.auth.models import User
class BasicBackend:
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
class EmailBackend(BasicBackend):
def authenticate(self, username=None, password=None):
try:
user = User.objects.get(email=username)
except User.DoesNotExist:
return None
if user.check_password(password):
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment