1
0
mirror of https://github.com/django/django.git synced 2025-10-27 15:46:10 +00:00

[1.7.x] Fixed #22771 -- Fixed test.Client.logout when using custom auth backend.

Backport of 50b9313e0a from master
This commit is contained in:
Xavier Fernandez
2014-06-06 11:19:16 +02:00
committed by Tim Graham
parent d4305a15c1
commit 183e9d2029
3 changed files with 41 additions and 5 deletions

View File

@@ -0,0 +1,20 @@
from django.contrib.auth.backends import ModelBackend
from .models import CustomUser
class CustomUserBackend(ModelBackend):
def authenticate(self, 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