mirror of https://github.com/jumpserver/jumpserver
perf: 企业微信、钉钉、飞书本地没有用户即创建
parent
3f1858a105
commit
185f33c3e0
|
@ -25,11 +25,9 @@ class BaseLoginCallbackView(AuthMixin, FlashMessageMixin, View):
|
||||||
client_auth_params = {}
|
client_auth_params = {}
|
||||||
user_type = ''
|
user_type = ''
|
||||||
auth_backend = None
|
auth_backend = None
|
||||||
create_user_if_not_exist_setting = ''
|
|
||||||
# 提示信息
|
# 提示信息
|
||||||
msg_client_err = _('Error')
|
msg_client_err = _('Error')
|
||||||
msg_user_not_bound_err = _('Error')
|
msg_user_not_bound_err = _('Error')
|
||||||
msg_user_need_bound_warning = _('Error')
|
|
||||||
msg_not_found_user_from_client_err = _('Error')
|
msg_not_found_user_from_client_err = _('Error')
|
||||||
|
|
||||||
def verify_state(self):
|
def verify_state(self):
|
||||||
|
@ -49,11 +47,6 @@ class BaseLoginCallbackView(AuthMixin, FlashMessageMixin, View):
|
||||||
|
|
||||||
def create_user_if_not_exist(self, user_id, **kwargs):
|
def create_user_if_not_exist(self, user_id, **kwargs):
|
||||||
user = None
|
user = None
|
||||||
if not getattr(settings, self.create_user_if_not_exist_setting):
|
|
||||||
title = self.msg_client_err
|
|
||||||
msg = self.msg_user_need_bound_warning
|
|
||||||
return user, (title, msg)
|
|
||||||
|
|
||||||
user_attr = self.client.get_user_detail(user_id, **kwargs)
|
user_attr = self.client.get_user_detail(user_id, **kwargs)
|
||||||
try:
|
try:
|
||||||
user, create = User.objects.get_or_create(
|
user, create = User.objects.get_or_create(
|
||||||
|
|
|
@ -205,11 +205,9 @@ class DingTalkQRLoginCallbackView(DingTalkQRMixin, BaseLoginCallbackView):
|
||||||
}
|
}
|
||||||
user_type = 'dingtalk'
|
user_type = 'dingtalk'
|
||||||
auth_backend = 'AUTH_BACKEND_DINGTALK'
|
auth_backend = 'AUTH_BACKEND_DINGTALK'
|
||||||
create_user_if_not_exist_setting = 'DINGTALK_CREATE_USER_IF_NOT_EXIST'
|
|
||||||
|
|
||||||
msg_client_err = _('DingTalk Error')
|
msg_client_err = _('DingTalk Error')
|
||||||
msg_user_not_bound_err = _('DingTalk is not bound')
|
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')
|
msg_not_found_user_from_client_err = _('Failed to get user from DingTalk')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -162,10 +162,8 @@ class FeiShuQRLoginCallbackView(FeiShuQRMixin, BaseLoginCallbackView):
|
||||||
client_auth_params = {'app_id': 'FEISHU_APP_ID', 'app_secret': 'FEISHU_APP_SECRET'}
|
client_auth_params = {'app_id': 'FEISHU_APP_ID', 'app_secret': 'FEISHU_APP_SECRET'}
|
||||||
user_type = 'feishu'
|
user_type = 'feishu'
|
||||||
auth_backend = 'AUTH_BACKEND_FEISHU'
|
auth_backend = 'AUTH_BACKEND_FEISHU'
|
||||||
create_user_if_not_exist_setting = 'FEISHU_CREATE_USER_IF_NOT_EXIST'
|
|
||||||
|
|
||||||
msg_client_err = _('FeiShu Error')
|
msg_client_err = _('FeiShu Error')
|
||||||
msg_user_not_bound_err = _('FeiShu is not bound')
|
msg_user_not_bound_err = _('FeiShu is not bound')
|
||||||
msg_user_need_bound_warning = _('Please login with a password and then bind the FeiShu')
|
|
||||||
msg_not_found_user_from_client_err = _('Failed to get user from FeiShu')
|
msg_not_found_user_from_client_err = _('Failed to get user from FeiShu')
|
||||||
|
|
||||||
|
|
|
@ -197,11 +197,9 @@ class WeComQRLoginCallbackView(WeComQRMixin, BaseLoginCallbackView):
|
||||||
client_auth_params = {'corpid': 'WECOM_CORPID', 'corpsecret': 'WECOM_SECRET', 'agentid': 'WECOM_AGENTID'}
|
client_auth_params = {'corpid': 'WECOM_CORPID', 'corpsecret': 'WECOM_SECRET', 'agentid': 'WECOM_AGENTID'}
|
||||||
user_type = 'wecom'
|
user_type = 'wecom'
|
||||||
auth_backend = 'AUTH_BACKEND_WECOM'
|
auth_backend = 'AUTH_BACKEND_WECOM'
|
||||||
create_user_if_not_exist_setting = 'WECOM_CREATE_USER_IF_NOT_EXIST'
|
|
||||||
|
|
||||||
msg_client_err = _('WeCom Error')
|
msg_client_err = _('WeCom Error')
|
||||||
msg_user_not_bound_err = _('WeCom is not bound')
|
msg_user_not_bound_err = _('WeCom is not bound')
|
||||||
msg_user_need_bound_warning = _('Please login with a password and then bind the WeCom')
|
|
||||||
msg_not_found_user_from_client_err = _('Failed to get user from WeCom')
|
msg_not_found_user_from_client_err = _('Failed to get user from WeCom')
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -365,21 +365,18 @@ class Config(dict):
|
||||||
'WECOM_CORPID': '',
|
'WECOM_CORPID': '',
|
||||||
'WECOM_AGENTID': '',
|
'WECOM_AGENTID': '',
|
||||||
'WECOM_SECRET': '',
|
'WECOM_SECRET': '',
|
||||||
'WECOM_CREATE_USER_IF_NOT_EXIST': False,
|
|
||||||
|
|
||||||
# 钉钉
|
# 钉钉
|
||||||
'AUTH_DINGTALK': False,
|
'AUTH_DINGTALK': False,
|
||||||
'DINGTALK_AGENTID': '',
|
'DINGTALK_AGENTID': '',
|
||||||
'DINGTALK_APPKEY': '',
|
'DINGTALK_APPKEY': '',
|
||||||
'DINGTALK_APPSECRET': '',
|
'DINGTALK_APPSECRET': '',
|
||||||
'DINGTALK_CREATE_USER_IF_NOT_EXIST': False,
|
|
||||||
|
|
||||||
# 飞书
|
# 飞书
|
||||||
'AUTH_FEISHU': False,
|
'AUTH_FEISHU': False,
|
||||||
'FEISHU_APP_ID': '',
|
'FEISHU_APP_ID': '',
|
||||||
'FEISHU_APP_SECRET': '',
|
'FEISHU_APP_SECRET': '',
|
||||||
'FEISHU_VERSION': 'feishu',
|
'FEISHU_VERSION': 'feishu',
|
||||||
'FEISHU_CREATE_USER_IF_NOT_EXIST': False,
|
|
||||||
|
|
||||||
'LOGIN_REDIRECT_TO_BACKEND': '', # 'OPENID / CAS / SAML2
|
'LOGIN_REDIRECT_TO_BACKEND': '', # 'OPENID / CAS / SAML2
|
||||||
'LOGIN_REDIRECT_MSG_ENABLED': True,
|
'LOGIN_REDIRECT_MSG_ENABLED': True,
|
||||||
|
|
|
@ -13,6 +13,3 @@ class DingTalkSettingSerializer(serializers.Serializer):
|
||||||
DINGTALK_APPKEY = serializers.CharField(max_length=256, required=True, label='AppKey')
|
DINGTALK_APPKEY = serializers.CharField(max_length=256, required=True, label='AppKey')
|
||||||
DINGTALK_APPSECRET = EncryptedField(max_length=256, required=False, label='AppSecret')
|
DINGTALK_APPSECRET = EncryptedField(max_length=256, required=False, label='AppSecret')
|
||||||
AUTH_DINGTALK = serializers.BooleanField(default=False, label=_('Enable DingTalk Auth'))
|
AUTH_DINGTALK = serializers.BooleanField(default=False, label=_('Enable DingTalk Auth'))
|
||||||
DINGTALK_CREATE_USER_IF_NOT_EXIST = serializers.BooleanField(
|
|
||||||
default=False, label=_('Create user if not')
|
|
||||||
)
|
|
||||||
|
|
|
@ -19,6 +19,3 @@ class FeiShuSettingSerializer(serializers.Serializer):
|
||||||
FEISHU_VERSION = serializers.ChoiceField(
|
FEISHU_VERSION = serializers.ChoiceField(
|
||||||
choices=VERSION_CHOICES, default='feishu', label=_('Version')
|
choices=VERSION_CHOICES, default='feishu', label=_('Version')
|
||||||
)
|
)
|
||||||
FEISHU_CREATE_USER_IF_NOT_EXIST = serializers.BooleanField(
|
|
||||||
default=False, label=_('Create user if not')
|
|
||||||
)
|
|
||||||
|
|
|
@ -13,6 +13,3 @@ class WeComSettingSerializer(serializers.Serializer):
|
||||||
WECOM_AGENTID = serializers.CharField(max_length=256, required=True, label='agentid')
|
WECOM_AGENTID = serializers.CharField(max_length=256, required=True, label='agentid')
|
||||||
WECOM_SECRET = EncryptedField(max_length=256, required=False, label='secret')
|
WECOM_SECRET = EncryptedField(max_length=256, required=False, label='secret')
|
||||||
AUTH_WECOM = serializers.BooleanField(default=False, label=_('Enable WeCom Auth'))
|
AUTH_WECOM = serializers.BooleanField(default=False, label=_('Enable WeCom Auth'))
|
||||||
WECOM_CREATE_USER_IF_NOT_EXIST = serializers.BooleanField(
|
|
||||||
default=False, label=_('Create user if not')
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue