2014-06-06 09:19:16 +00:00
|
|
|
from django.contrib.auth.backends import ModelBackend
|
|
|
|
|
|
|
|
from .models import CustomUser
|
|
|
|
|
|
|
|
|
|
|
|
class CustomUserBackend(ModelBackend):
|
|
|
|
|
2016-07-11 14:40:39 +00:00
|
|
|
def authenticate(self, request, username=None, password=None):
|
2014-06-06 09:19:16 +00:00
|
|
|
try:
|
|
|
|
user = CustomUser.custom_objects.get_by_natural_key(username)
|
|
|
|
if user.check_password(password):
|
|
|
|
return user
|
|
|
|
except CustomUser.DoesNotExist:
|
|
|
|
return None
|
|
|
|
|
|
|
|
def get_user(self, user_id):
|
|
|
|
try:
|
|
|
|
return CustomUser.custom_objects.get(pk=user_id)
|
|
|
|
except CustomUser.DoesNotExist:
|
|
|
|
return None
|