mirror of
https://github.com/django/django.git
synced 2024-12-27 11:35:53 +00:00
21 lines
592 B
Python
21 lines
592 B
Python
from django.contrib.auth.backends import ModelBackend
|
|
|
|
from .models import CustomUser
|
|
|
|
|
|
class CustomUserBackend(ModelBackend):
|
|
|
|
def authenticate(self, request, username=None, password=None):
|
|
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
|