From 5a9c91d9dd1fa3fd268826884a516966ffb6d3e2 Mon Sep 17 00:00:00 2001 From: xinwen Date: Wed, 19 Aug 2020 13:10:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(authentication):=20=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=88=90=E5=91=98=E7=A6=81=E7=94=A8=E5=86=8D=E6=BF=80=E6=B4=BB?= =?UTF-8?q?=EF=BC=8C=E7=99=BB=E5=BD=95=E6=8A=A5=E9=94=99=20#239?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/mixins.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index 38a8a852c..e2da6b8e5 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -7,6 +7,7 @@ import time from django.conf import settings from django.contrib.auth import authenticate from django.shortcuts import reverse +from django.contrib.auth import BACKEND_SESSION_KEY from common.utils import get_object_or_none, get_request_ip, get_logger from users.models import User @@ -27,8 +28,14 @@ class AuthMixin: def get_user_from_session(self): if self.request.session.is_empty(): raise errors.SessionEmptyError() - if self.request.user and not self.request.user.is_anonymous: - return self.request.user + + if all((self.request.user, + not self.request.user.is_anonymous, + BACKEND_SESSION_KEY in self.request.session)): + user = self.request.user + user.backend = self.request.session[BACKEND_SESSION_KEY] + return user + user_id = self.request.session.get('user_id') if not user_id: user = None