UnisKB/ui/src/views/authentication/component/LDAP.vue

188 lines
5.4 KiB
Vue
Raw Normal View History

2024-07-09 09:50:37 +00:00
<template>
2024-10-09 02:59:45 +00:00
<div class="authentication-setting__main main-calc-height">
<el-scrollbar>
<div class="form-container p-24" v-loading="loading">
<el-form
ref="authFormRef"
:rules="rules"
:model="form"
label-position="top"
require-asterisk-position="right"
>
2025-01-13 03:15:51 +00:00
<el-form-item
:label="$t('views.system.authentication.ldap.address')"
prop="config_data.ldap_server"
>
2024-10-09 02:59:45 +00:00
<el-input
v-model="form.config_data.ldap_server"
2025-01-13 03:15:51 +00:00
:placeholder="$t('views.system.authentication.ldap.serverPlaceholder')"
2024-10-09 02:59:45 +00:00
/>
</el-form-item>
2025-01-13 03:15:51 +00:00
<el-form-item
:label="$t('views.system.authentication.ldap.bindDN')"
prop="config_data.base_dn"
>
2024-10-09 02:59:45 +00:00
<el-input
v-model="form.config_data.base_dn"
2025-01-13 03:15:51 +00:00
:placeholder="$t('views.system.authentication.ldap.bindDNPlaceholder')"
2024-10-09 02:59:45 +00:00
/>
</el-form-item>
2025-01-13 03:15:51 +00:00
<el-form-item
:label="$t('views.system.authentication.ldap.password')"
prop="config_data.password"
>
2024-10-09 02:59:45 +00:00
<el-input
v-model="form.config_data.password"
2025-01-21 07:25:21 +00:00
:placeholder="$t('views.user.userForm.form.password.placeholder')"
2024-10-09 02:59:45 +00:00
show-password
/>
</el-form-item>
2025-01-13 03:15:51 +00:00
<el-form-item :label="$t('views.system.authentication.ldap.ou')" prop="config_data.ou">
<el-input
v-model="form.config_data.ou"
:placeholder="$t('views.system.authentication.ldap.ouPlaceholder')"
/>
2024-10-09 02:59:45 +00:00
</el-form-item>
2025-01-13 03:15:51 +00:00
<el-form-item
:label="$t('views.system.authentication.ldap.ldap_filter')"
prop="config_data.ldap_filter"
>
2024-10-09 02:59:45 +00:00
<el-input
v-model="form.config_data.ldap_filter"
2025-01-13 03:15:51 +00:00
:placeholder="$t('views.system.authentication.ldap.ldap_filterPlaceholder')"
2024-10-09 02:59:45 +00:00
/>
</el-form-item>
2025-01-13 03:15:51 +00:00
<el-form-item
:label="$t('views.system.authentication.ldap.ldap_mapping')"
prop="config_data.ldap_mapping"
>
2024-10-09 02:59:45 +00:00
<el-input
v-model="form.config_data.ldap_mapping"
placeholder='{"name":"name","email":"mail","username":"cn"}'
/>
</el-form-item>
<el-form-item>
<el-checkbox v-model="form.is_active">{{
2025-01-13 03:15:51 +00:00
$t('views.system.authentication.ldap.enableAuthentication')
2024-10-09 02:59:45 +00:00
}}</el-checkbox>
</el-form-item>
</el-form>
2024-07-09 09:50:37 +00:00
2024-10-09 02:59:45 +00:00
<div class="text-right">
2024-11-22 09:05:18 +00:00
<el-button @click="submit(authFormRef, 'test')" :disabled="loading">
2025-01-22 08:46:12 +00:00
{{ $t('views.system.test') }}</el-button
2024-11-22 09:05:18 +00:00
>
2024-10-09 02:59:45 +00:00
<el-button @click="submit(authFormRef)" type="primary" :disabled="loading">
2025-01-13 03:15:51 +00:00
{{ $t('common.save') }}
2024-10-09 02:59:45 +00:00
</el-button>
</div>
</div>
</el-scrollbar>
2024-07-09 09:50:37 +00:00
</div>
</template>
<script setup lang="ts">
2024-08-14 10:54:32 +00:00
import { reactive, ref, watch, onMounted } from 'vue'
2024-07-11 11:51:28 +00:00
import authApi from '@/api/auth-setting'
2024-08-14 10:54:32 +00:00
import type { FormInstance, FormRules } from 'element-plus'
import { t } from '@/locales'
import { MsgSuccess } from '@/utils/message'
2024-07-09 09:50:37 +00:00
const form = ref<any>({
2024-07-11 11:51:28 +00:00
id: '',
auth_type: 'LDAP',
config_data: {
ldap_server: '',
base_dn: '',
password: '',
ou: '',
ldap_filter: '',
2024-08-14 10:54:32 +00:00
ldap_mapping: ''
2024-07-11 11:51:28 +00:00
},
is_active: true
2024-07-09 09:50:37 +00:00
})
2024-07-11 11:51:28 +00:00
const authFormRef = ref()
2024-07-09 09:50:37 +00:00
const loading = ref(false)
const rules = reactive<FormRules<any>>({
2024-08-14 10:54:32 +00:00
'config_data.ldap_server': [
2025-01-13 03:15:51 +00:00
{
required: true,
message: t('views.system.authentication.ldap.serverPlaceholder'),
trigger: 'blur'
}
2024-08-14 10:54:32 +00:00
],
'config_data.base_dn': [
2025-01-13 03:15:51 +00:00
{
required: true,
message: t('views.system.authentication.ldap.bindDNPlaceholder'),
trigger: 'blur'
}
2024-08-14 10:54:32 +00:00
],
'config_data.password': [
2025-01-13 03:15:51 +00:00
{
required: true,
2025-01-21 07:25:21 +00:00
message: t('views.user.userForm.form.password.requiredMessage'),
2025-01-13 03:15:51 +00:00
trigger: 'blur'
}
],
'config_data.ou': [
{
required: true,
message: t('views.system.authentication.ldap.ouPlaceholder'),
trigger: 'blur'
}
2024-08-14 10:54:32 +00:00
],
'config_data.ldap_filter': [
2025-01-13 03:15:51 +00:00
{
required: true,
message: t('views.system.authentication.ldap.ldap_filterPlaceholder'),
trigger: 'blur'
}
2024-08-14 10:54:32 +00:00
],
'config_data.ldap_mapping': [
2025-01-13 03:15:51 +00:00
{
required: true,
message: t('views.system.authentication.ldap.ldap_mappingPlaceholder'),
trigger: 'blur'
}
2024-08-14 10:54:32 +00:00
]
2024-07-09 09:50:37 +00:00
})
const submit = async (formEl: FormInstance | undefined, test?: string) => {
if (!formEl) return
await formEl.validate((valid, fields) => {
if (valid) {
if (test) {
2024-07-11 11:51:28 +00:00
authApi.postAuthSetting(form.value, loading).then((res) => {
2025-01-22 08:46:12 +00:00
MsgSuccess(t('views.system.testFailed'))
2024-07-09 09:50:37 +00:00
})
} else {
2024-07-11 11:51:28 +00:00
authApi.putAuthSetting(form.value.auth_type, form.value, loading).then((res) => {
2025-01-13 03:15:51 +00:00
MsgSuccess(t('common.saveSuccess'))
2024-07-09 09:50:37 +00:00
})
}
}
})
}
function getDetail() {
2024-07-11 11:51:28 +00:00
authApi.getAuthSetting(form.value.auth_type, loading).then((res: any) => {
2024-07-09 09:50:37 +00:00
if (res.data && JSON.stringify(res.data) !== '{}') {
form.value = res.data
2024-07-11 11:51:28 +00:00
if (res.data.config_data.ldap_mapping) {
2024-08-14 10:54:32 +00:00
form.value.config_data.ldap_mapping = JSON.stringify(
JSON.parse(res.data.config_data.ldap_mapping)
)
2024-07-11 11:51:28 +00:00
}
2024-07-09 09:50:37 +00:00
}
})
}
onMounted(() => {
getDetail()
})
</script>
<style lang="scss" scoped></style>