From c8eb7cccb1dc3755bacd6b93ea585b48eb5b252a Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 24 Jul 2024 10:59:54 +0800 Subject: [PATCH] perf: Modify error message for desktop client login --- apps/authentication/views/base.py | 8 +++----- apps/authentication/views/dingtalk.py | 10 +--------- apps/authentication/views/feishu.py | 10 +--------- apps/authentication/views/mixins.py | 10 ++++++++++ apps/authentication/views/slack.py | 10 +--------- apps/authentication/views/wecom.py | 10 +--------- apps/i18n/core/en/LC_MESSAGES/django.po | 6 +++--- apps/i18n/core/ja/LC_MESSAGES/django.po | 11 +++++++---- apps/i18n/core/zh/LC_MESSAGES/django.po | 9 +++++---- apps/i18n/core/zh_Hant/LC_MESSAGES/django.po | 9 +++++---- 10 files changed, 37 insertions(+), 56 deletions(-) diff --git a/apps/authentication/views/base.py b/apps/authentication/views/base.py index 8146e1cd2..7e4cf8692 100644 --- a/apps/authentication/views/base.py +++ b/apps/authentication/views/base.py @@ -151,11 +151,9 @@ class BaseBindCallbackView(FlashMessageMixin, IMClientMixin, View): setattr(user, f'{self.auth_type}_id', auth_user_id) user.save() except IntegrityError as e: - if e.args[0] == 1062: - msg = _('The %s is already bound to another user') % self.auth_type_label - response = self.get_failed_response(redirect_url, msg, msg) - return response - raise e + msg = _('The %s is already bound to another user') % self.auth_type_label + response = self.get_failed_response(redirect_url, msg, msg) + return response ip = get_request_ip(request) OAuthBindMessage(user, ip, self.auth_type_label, auth_user_id).publish_async() diff --git a/apps/authentication/views/dingtalk.py b/apps/authentication/views/dingtalk.py index 650bfe9c8..85680dde1 100644 --- a/apps/authentication/views/dingtalk.py +++ b/apps/authentication/views/dingtalk.py @@ -47,15 +47,7 @@ class DingTalkBaseMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, Fla ) def verify_state(self): - state = self.request.GET.get('state') - session_state = self.request.session.get(DINGTALK_STATE_SESSION_KEY) - if state != session_state: - return False - return True - - def get_verify_state_failed_response(self, redirect_uri): - msg = _("The system configuration is incorrect. Please contact your administrator") - return self.get_failed_response(redirect_uri, msg, msg) + return self.verify_state_with_session_key(DINGTALK_STATE_SESSION_KEY) def get_already_bound_response(self, redirect_url): msg = _('DingTalk is already bound') diff --git a/apps/authentication/views/feishu.py b/apps/authentication/views/feishu.py index c2cd07914..67e0040d5 100644 --- a/apps/authentication/views/feishu.py +++ b/apps/authentication/views/feishu.py @@ -58,15 +58,7 @@ class FeiShuQRMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, FlashMe ) def verify_state(self): - state = self.request.GET.get('state') - session_state = self.request.session.get(self.state_session_key) - if state != session_state: - return False - return True - - def get_verify_state_failed_response(self, redirect_uri): - msg = _("The system configuration is incorrect. Please contact your administrator") - return self.get_failed_response(redirect_uri, msg, msg) + return self.verify_state_with_session_key(self.state_session_key) def get_qr_url(self, redirect_uri): state = random_string(16) diff --git a/apps/authentication/views/mixins.py b/apps/authentication/views/mixins.py index c78872603..d6818f158 100644 --- a/apps/authentication/views/mixins.py +++ b/apps/authentication/views/mixins.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- # +from django.utils.translation import gettext_lazy as _ from common.utils import FlashMessageUtil @@ -32,3 +33,12 @@ class FlashMessageMixin: def get_failed_response(self, redirect_url, title, msg, interval=10): return self.get_response(redirect_url, title, msg, 'error', interval) + + def get_verify_state_failed_response(self, redirect_uri): + msg = _( + "For your safety, automatic redirection login is not supported on the client." + " If you need to open it in the client, please log in again") + return self.get_failed_response(redirect_uri, msg, msg) + + def verify_state_with_session_key(self, session_key): + return self.request.GET.get('state') == self.request.session.get(session_key) diff --git a/apps/authentication/views/slack.py b/apps/authentication/views/slack.py index 70edcf4c5..912fe89ef 100644 --- a/apps/authentication/views/slack.py +++ b/apps/authentication/views/slack.py @@ -37,15 +37,7 @@ class SlackMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, FlashMessa ) def verify_state(self): - state = self.request.GET.get('state') - session_state = self.request.session.get(SLACK_STATE_SESSION_KEY) - if state != session_state: - return False - return True - - def get_verify_state_failed_response(self, redirect_uri): - msg = _("The system configuration is incorrect. Please contact your administrator") - return self.get_failed_response(redirect_uri, msg, msg) + return self.verify_state_with_session_key(SLACK_STATE_SESSION_KEY) def get_qr_url(self, redirect_uri): state = random_string(16) diff --git a/apps/authentication/views/wecom.py b/apps/authentication/views/wecom.py index 48268e516..c41e20338 100644 --- a/apps/authentication/views/wecom.py +++ b/apps/authentication/views/wecom.py @@ -45,15 +45,7 @@ class WeComBaseMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, FlashM ) def verify_state(self): - state = self.request.GET.get('state') - session_state = self.request.session.get(WECOM_STATE_SESSION_KEY) - if state != session_state: - return False - return True - - def get_verify_state_failed_response(self, redirect_uri): - msg = _("The system configuration is incorrect. Please contact your administrator") - return self.get_failed_response(redirect_uri, msg, msg) + return self.verify_state_with_session_key(WECOM_STATE_SESSION_KEY) def get_already_bound_response(self, redirect_url): msg = _('WeCom is already bound') diff --git a/apps/i18n/core/en/LC_MESSAGES/django.po b/apps/i18n/core/en/LC_MESSAGES/django.po index 5bab4a3c6..70bddadd4 100644 --- a/apps/i18n/core/en/LC_MESSAGES/django.po +++ b/apps/i18n/core/en/LC_MESSAGES/django.po @@ -3630,10 +3630,10 @@ msgstr "" msgid "DingTalk Error" msgstr "" -#: authentication/views/dingtalk.py:57 authentication/views/feishu.py:68 -#: authentication/views/slack.py:47 authentication/views/wecom.py:55 +#: authentication/views/mixins.py:39 msgid "" -"The system configuration is incorrect. Please contact your administrator" +"For your safety, automatic redirection login is not supported on the client. " +"If you need to open it in the client, please log in again" msgstr "" #: authentication/views/dingtalk.py:61 diff --git a/apps/i18n/core/ja/LC_MESSAGES/django.po b/apps/i18n/core/ja/LC_MESSAGES/django.po index 9db6c9678..e2d0cffd1 100644 --- a/apps/i18n/core/ja/LC_MESSAGES/django.po +++ b/apps/i18n/core/ja/LC_MESSAGES/django.po @@ -3709,11 +3709,14 @@ msgstr "DingTalkエラー、システム管理者に連絡してください" msgid "DingTalk Error" msgstr "DingTalkエラー" -#: authentication/views/dingtalk.py:57 authentication/views/feishu.py:68 -#: authentication/views/slack.py:47 authentication/views/wecom.py:55 +#: authentication/views/mixins.py:39 msgid "" -"The system configuration is incorrect. Please contact your administrator" -msgstr "システム設定が正しくありません。管理者に連絡してください" +"For your safety, automatic redirection login is not supported on the client. " +"If you need to open it in the client, please log in again" +msgstr "" +"安全のため、クライアントでの自動リダイレクトログインはサポートされていませ" +"ん。クライアントで開く必要がある場合は、再度ログインしてください" + #: authentication/views/dingtalk.py:61 msgid "DingTalk is already bound" diff --git a/apps/i18n/core/zh/LC_MESSAGES/django.po b/apps/i18n/core/zh/LC_MESSAGES/django.po index 75320b6d7..089008ad6 100644 --- a/apps/i18n/core/zh/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh/LC_MESSAGES/django.po @@ -3659,11 +3659,12 @@ msgstr "钉钉错误,请联系系统管理员" msgid "DingTalk Error" msgstr "钉钉错误" -#: authentication/views/dingtalk.py:57 authentication/views/feishu.py:68 -#: authentication/views/slack.py:47 authentication/views/wecom.py:55 +#: authentication/views/mixins.py:39 msgid "" -"The system configuration is incorrect. Please contact your administrator" -msgstr "企业配置错误,请联系系统管理员" +"For your safety, automatic redirection login is not supported on the client. " +"If you need to open it in the client, please log in again" +msgstr "" +"为了您的安全,客户端不支持自动跳转登录。如果需要在客户端中打开,请重新登录" #: authentication/views/dingtalk.py:61 msgid "DingTalk is already bound" diff --git a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po index b6e6c4291..16983127d 100644 --- a/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po +++ b/apps/i18n/core/zh_Hant/LC_MESSAGES/django.po @@ -3661,11 +3661,12 @@ msgstr "釘釘錯誤,請聯絡系統管理員" msgid "DingTalk Error" msgstr "釘釘錯誤" -#: authentication/views/dingtalk.py:57 authentication/views/feishu.py:68 -#: authentication/views/slack.py:47 authentication/views/wecom.py:55 +#: authentication/views/mixins.py:39 msgid "" -"The system configuration is incorrect. Please contact your administrator" -msgstr "企業配置錯誤,請聯絡系統管理員" +"For your safety, automatic redirection login is not supported on the client. " +"If you need to open it in the client, please log in again" +msgstr "" +"為了您的安全,客戶端不支持自動跳轉登錄。如果需要在客戶端中打開,請重新登錄" #: authentication/views/dingtalk.py:61 msgid "DingTalk is already bound"