diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py index d37450805f9..14ae0206746 100644 --- a/django/contrib/auth/__init__.py +++ b/django/contrib/auth/__init__.py @@ -53,6 +53,8 @@ def login(request, user): user.save() request.session[SESSION_KEY] = user.id request.session[BACKEND_SESSION_KEY] = user.backend + if hasattr(request, 'user'): + request.user = user def logout(request): """ @@ -66,6 +68,9 @@ def logout(request): del request.session[BACKEND_SESSION_KEY] except KeyError: pass + if hasattr(request, 'user'): + from django.contrib.auth.models import AnonymousUser + request.user = AnonymousUser() def get_user(request): from django.contrib.auth.models import AnonymousUser