Skip to content

Commit

Permalink
perf: Modify error message for desktop client login (jumpserver#13763)
Browse files Browse the repository at this point in the history
* perf: Modify error message for desktop client login

* perf: Update Dockerfile with new base image tag

---------

Co-authored-by: wangruidong <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent ef656a8 commit 03a66fd
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM jumpserver/core-base:20240722_031104 AS stage-build
FROM jumpserver/core-base:20240724_024214 AS stage-build

ARG VERSION

Expand Down
8 changes: 3 additions & 5 deletions apps/authentication/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ def get(self, request: Request):
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()
Expand Down
10 changes: 1 addition & 9 deletions apps/authentication/views/dingtalk.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,7 @@ def dispatch(self, request, *args, **kwargs):
)

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')
Expand Down
10 changes: 1 addition & 9 deletions apps/authentication/views/feishu.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,7 @@ def dispatch(self, request, *args, **kwargs):
)

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)
Expand Down
10 changes: 10 additions & 0 deletions apps/authentication/views/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
#
from django.utils.translation import gettext_lazy as _
from common.utils import FlashMessageUtil


Expand Down Expand Up @@ -32,3 +33,12 @@ def get_success_response(self, redirect_url, title, msg, **kwargs):

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)
10 changes: 1 addition & 9 deletions apps/authentication/views/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@ def dispatch(self, request, *args, **kwargs):
)

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)
Expand Down
10 changes: 1 addition & 9 deletions apps/authentication/views/wecom.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ def dispatch(self, request, *args, **kwargs):
)

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')
Expand Down
6 changes: 3 additions & 3 deletions apps/i18n/core/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3641,10 +3641,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
Expand Down
11 changes: 7 additions & 4 deletions apps/i18n/core/ja/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3720,11 +3720,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"
Expand Down
9 changes: 5 additions & 4 deletions apps/i18n/core/zh/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3670,11 +3670,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"
Expand Down
9 changes: 5 additions & 4 deletions apps/i18n/core/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -3672,11 +3672,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"
Expand Down

0 comments on commit 03a66fd

Please sign in to comment.