From 75d2c81d33a05a2e88998b5087aa5e882f051d76 Mon Sep 17 00:00:00 2001 From: ibuler Date: Sat, 18 Sep 2021 15:24:04 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/authentication/views/login.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/authentication/views/login.py b/apps/authentication/views/login.py index a916db1bc..07fa7cc5a 100644 --- a/apps/authentication/views/login.py +++ b/apps/authentication/views/login.py @@ -122,7 +122,11 @@ class UserLoginView(mixins.AuthMixin, FormView): context = self.get_context_data(form=new_form) self.request.session.set_test_cookie() return self.render_to_response(context) - except (errors.PasswdTooSimple, errors.PasswordRequireResetError, errors.PasswdNeedUpdate) as e: + except ( + errors.PasswdTooSimple, + errors.PasswordRequireResetError, + errors.PasswdNeedUpdate + ) as e: return redirect(e.url) self.clear_rsa_key() return self.redirect_to_guard_view() @@ -174,22 +178,19 @@ class UserLoginView(mixins.AuthMixin, FormView): return [method for method in auth_methods] # return [method for method in auth_methods if method['enabled']] - def get_context_data(self, **kwargs): + @staticmethod + def get_forgot_password_url(): forgot_password_url = reverse('authentication:forgot-password') has_other_auth_backend = settings.AUTHENTICATION_BACKENDS[0] != settings.AUTH_BACKEND_MODEL if has_other_auth_backend and settings.FORGOT_PASSWORD_URL: forgot_password_url = settings.FORGOT_PASSWORD_URL + return forgot_password_url + def get_context_data(self, **kwargs): context = { 'demo_mode': os.environ.get("DEMO_MODE"), 'auth_methods': self.get_support_auth_methods(), - 'has_other_auth' - 'AUTH_OPENID': settings.AUTH_OPENID, - 'AUTH_CAS': settings.AUTH_CAS, - 'AUTH_WECOM': settings.AUTH_WECOM, - 'AUTH_DINGTALK': settings.AUTH_DINGTALK, - 'AUTH_FEISHU': settings.AUTH_FEISHU, - 'forgot_password_url': forgot_password_url + 'forgot_password_url': self.get_forgot_password_url() } kwargs.update(context) return super().get_context_data(**kwargs)