You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.0 KiB

from django.contrib.auth.models import User
from hc.accounts.models import Profile
class BasicBackend(object):
def get_user(self, user_id):
try:
return User.objects.select_related("profile").get(pk=user_id)
except User.DoesNotExist:
return None
# Authenticate against the token in user's profile.
class ProfileBackend(BasicBackend):
def authenticate(self, request=None, username=None, token=None):
try:
profiles = Profile.objects.select_related("user")
profile = profiles.get(user__username=username)
except Profile.DoesNotExist:
return None
if not profile.check_token(token, "login"):
return None
return profile.user
class EmailBackend(BasicBackend):
def authenticate(self, request=None, username=None, password=None):
try:
user = User.objects.get(email=username)
except User.DoesNotExist:
return None
if user.check_password(password):
return user