mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-03 08:25:04 +00:00
perf: 优化逻辑,抽离callback_base类
This commit is contained in:
committed by
Jiangjie.Bai
parent
7a97496f70
commit
3367f65b02
@@ -23,14 +23,15 @@ from common.utils.random import random_string
|
||||
from users.models import User
|
||||
from users.views import UserVerifyPasswordView
|
||||
|
||||
from .mixins import METAMixin, QRLoginCallbackMixin
|
||||
from .base import BaseLoginCallbackView
|
||||
from .mixins import METAMixin, FlashMessageMixin
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
DINGTALK_STATE_SESSION_KEY = '_dingtalk_state'
|
||||
|
||||
|
||||
class DingTalkBaseMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, View):
|
||||
class DingTalkBaseMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, FlashMessageMixin, View):
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
try:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
@@ -56,26 +57,6 @@ class DingTalkBaseMixin(UserConfirmRequiredExceptionMixin, PermissionsMixin, Vie
|
||||
msg = _("The system configuration is incorrect. Please contact your administrator")
|
||||
return self.get_failed_response(redirect_uri, msg, msg)
|
||||
|
||||
@staticmethod
|
||||
def get_success_response(redirect_url, title, msg):
|
||||
message_data = {
|
||||
'title': title,
|
||||
'message': msg,
|
||||
'interval': 5,
|
||||
'redirect_url': redirect_url,
|
||||
}
|
||||
return FlashMessageUtil.gen_and_redirect_to(message_data)
|
||||
|
||||
@staticmethod
|
||||
def get_failed_response(redirect_url, title, msg):
|
||||
message_data = {
|
||||
'title': title,
|
||||
'error': msg,
|
||||
'interval': 5,
|
||||
'redirect_url': redirect_url,
|
||||
}
|
||||
return FlashMessageUtil.gen_and_redirect_to(message_data)
|
||||
|
||||
def get_already_bound_response(self, redirect_url):
|
||||
msg = _('DingTalk is already bound')
|
||||
response = self.get_failed_response(redirect_url, msg, msg)
|
||||
@@ -214,20 +195,21 @@ class DingTalkQRLoginView(DingTalkQRMixin, METAMixin, View):
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
|
||||
class DingTalkQRLoginCallbackView(QRLoginCallbackMixin, AuthMixin, DingTalkQRMixin, View):
|
||||
class DingTalkQRLoginCallbackView(DingTalkQRMixin, BaseLoginCallbackView):
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
CLIENT_INFO = (
|
||||
DingTalk, {'appid': 'DINGTALK_APPKEY', 'appsecret': 'DINGTALK_APPSECRET', 'agentid': 'DINGTALK_AGENTID'}
|
||||
)
|
||||
USER_TYPE = 'dingtalk'
|
||||
AUTH_BACKEND = 'AUTH_BACKEND_DINGTALK'
|
||||
CREATE_USER_IF_NOT_EXIST = 'DINGTALK_CREATE_USER_IF_NOT_EXIST'
|
||||
def __init__(self):
|
||||
super(DingTalkQRLoginCallbackView, self).__init__()
|
||||
self.client_type = DingTalk
|
||||
self.client_auth_params = {'appid': 'DINGTALK_APPKEY', 'appsecret': 'DINGTALK_APPSECRET', 'agentid': 'DINGTALK_AGENTID'}
|
||||
self.user_type = 'dingtalk'
|
||||
self.auth_backend = 'AUTH_BACKEND_DINGTALK'
|
||||
self.create_user_if_not_exist_setting = 'DINGTALK_CREATE_USER_IF_NOT_EXIST'
|
||||
|
||||
MSG_CLIENT_ERR = _('DingTalk Error')
|
||||
MSG_USER_NOT_BOUND_ERR = _('DingTalk is not bound')
|
||||
MSG_USER_NEED_BOUND_WARNING = _('Please login with a password and then bind the DingTalk')
|
||||
MSG_NOT_FOUND_USER_FROM_CLIENT_ERR = _('Failed to get user from DingTalk')
|
||||
self.msg_client_err = _('DingTalk Error')
|
||||
self.msg_user_not_bound_err = _('DingTalk is not bound')
|
||||
self.msg_user_need_bound_warning = _('Please login with a password and then bind the DingTalk')
|
||||
self.msg_not_found_user_from_client_err = _('Failed to get user from DingTalk')
|
||||
|
||||
|
||||
class DingTalkOAuthLoginView(DingTalkOAuthMixin, View):
|
||||
|
Reference in New Issue
Block a user