From c7c0374c78d55ab6e1bc04b0a44130462129d555 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Tue, 12 Jul 2022 13:45:48 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=E4=B8=BB=E9=A2=98=20?= =?UTF-8?q?(#8569)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 优化登录 backend * perf: 修改主题 Co-authored-by: ibuler --- apps/authentication/mixins.py | 8 +++++--- apps/authentication/views/wecom.py | 1 - apps/templates/_head_css_js.html | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/authentication/mixins.py b/apps/authentication/mixins.py index 58e6ccd36..403f7186d 100644 --- a/apps/authentication/mixins.py +++ b/apps/authentication/mixins.py @@ -443,13 +443,15 @@ class AuthMixin(CommonMixin, AuthPreCheckMixin, AuthACLMixin, MFAMixin, AuthPost LoginIpBlockUtil(ip).clean_block_if_need() return user - def mark_password_ok(self, user, auto_login=False): + def mark_password_ok(self, user, auto_login=False, auth_backend=None): request = self.request request.session['auth_password'] = 1 request.session['auth_password_expired_at'] = time.time() + settings.AUTH_EXPIRED_SECONDS request.session['user_id'] = str(user.id) request.session['auto_login'] = auto_login - request.session['auth_backend'] = getattr(user, 'backend', settings.AUTH_BACKEND_MODEL) + if not auth_backend: + auth_backend = getattr(user, 'backend', settings.AUTH_BACKEND_MODEL) + request.session['auth_backend'] = auth_backend def check_oauth2_auth(self, user: User, auth_backend): ip = self.get_request_ip() @@ -469,7 +471,7 @@ class AuthMixin(CommonMixin, AuthPreCheckMixin, AuthACLMixin, MFAMixin, AuthPost LoginIpBlockUtil(ip).clean_block_if_need() MFABlockUtils(user.username, ip).clean_failed_count() - self.mark_password_ok(user, False) + self.mark_password_ok(user, False, auth_backend) return user def get_user_or_auth(self, valid_data): diff --git a/apps/authentication/views/wecom.py b/apps/authentication/views/wecom.py index c9315bdb5..b896aa19e 100644 --- a/apps/authentication/views/wecom.py +++ b/apps/authentication/views/wecom.py @@ -300,5 +300,4 @@ class WeComOAuthLoginCallbackView(AuthMixin, WeComOAuthMixin, View): msg = e.msg response = self.get_failed_response(login_url, title=msg, msg=msg) return response - return self.redirect_to_guard_view() diff --git a/apps/templates/_head_css_js.html b/apps/templates/_head_css_js.html index 2256882c5..718115dc8 100644 --- a/apps/templates/_head_css_js.html +++ b/apps/templates/_head_css_js.html @@ -22,8 +22,8 @@