perf: i18n Optimization for Third-Party Authentication Validation

This commit is contained in:
fit2cloud-chenyw
2025-12-02 15:36:25 +08:00
committed by fit2cloud-chenyw
parent f105a53dcb
commit 2ff3e10a0c
11 changed files with 65 additions and 15 deletions
+3
View File
@@ -114,5 +114,8 @@
},
"i18n_excel_import": {
"col_num_not_match": "Number of columns in Excel does not match"
},
"i18n_authentication": {
"record_not_exist": "{msg} record does not exist. Please save it first!"
}
}
+3
View File
@@ -114,5 +114,8 @@
},
"i18n_excel_import": {
"col_num_not_match": "Excel 열 개수가 일치하지 않습니다"
},
"i18n_authentication": {
"record_not_exist": "{msg} 기록이 존재하지 않습니다. 먼저 저장해 주세요!"
}
}
+3
View File
@@ -114,5 +114,8 @@
},
"i18n_excel_import": {
"col_num_not_match": "EXCEL列数量不匹配"
},
"i18n_authentication": {
"record_not_exist": "{msg} 记录不存在,请先保存!"
}
}
+1
View File
@@ -732,6 +732,7 @@
"valid": "Valid",
"cas_settings": "CAS Settings",
"callback_domain_name": "Callback Domain",
"callback_domain_name_error": "Callback URL must match the current access domain",
"field_mapping": "User Attribute Mapping",
"field_mapping_placeholder": "Example: {'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
"incorrect_please_re_enter": "Incorrect format, please re-enter",
+1
View File
@@ -732,6 +732,7 @@
"valid": "유효함",
"cas_settings": "CAS 설정",
"callback_domain_name": "콜백 도메인",
"callback_domain_name_error": "콜백 URL은 현재 접속 도메인과 일치해야 합니다",
"field_mapping": "사용자 속성 매핑",
"field_mapping_placeholder": "예: {'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
"incorrect_please_re_enter": "형식이 잘못되었습니다. 다시 입력해 주세요",
+1
View File
@@ -732,6 +732,7 @@
"valid": "有效",
"cas_settings": "CAS 设置",
"callback_domain_name": "回调地址",
"callback_domain_name_error": "回调地址必须是当前访问域名",
"field_mapping": "用户属性映射",
"field_mapping_placeholder": "例如:{'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
"incorrect_please_re_enter": "格式错误,请重新填写",
+8
View File
@@ -255,3 +255,11 @@ export function isMobile() {
) && !isTablet()
)
}
export const getSQLBotAddr = (portEnd?: boolean) => {
const addr = location.origin + location.pathname
if (!portEnd || !addr.endsWith('/')) {
return addr
}
return addr.substring(0, addr.length - 1)
}
@@ -4,6 +4,7 @@ import { ElMessage, ElLoading } from 'element-plus-secondary'
import { useI18n } from 'vue-i18n'
import type { FormInstance, FormRules } from 'element-plus-secondary'
import { request } from '@/utils/request'
import { getSQLBotAddr } from '@/utils/utils'
const { t } = useI18n()
const dialogVisible = ref(false)
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -17,7 +18,7 @@ interface CasForm {
const state = reactive({
form: reactive<CasForm>({
idpUri: '',
casCallbackDomain: '',
casCallbackDomain: getSQLBotAddr(),
mapping: '',
}),
})
@@ -33,6 +34,15 @@ const validateUrl = (rule, value, callback) => {
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const validateCbUrl = (rule, value, callback) => {
const addr = getSQLBotAddr()
if (value === addr || `${value}/` === addr) {
callback()
}
callback(new Error(t('authentication.callback_domain_name_error')))
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const validateMapping = (rule, value, callback) => {
if (!value) {
callback()
@@ -76,7 +86,7 @@ const rule = reactive<FormRules>({
message: t('commons.input_limit', [10, 255]),
trigger: 'blur',
},
{ required: true, validator: validateUrl, trigger: 'blur' },
{ required: true, validator: validateCbUrl, trigger: 'blur' },
],
mapping: [{ required: false, validator: validateMapping, trigger: 'blur' }],
})
@@ -11,6 +11,8 @@ import {
ElSelect,
} from 'element-plus-secondary'
import { request } from '@/utils/request'
import { getSQLBotAddr } from '@/utils/utils'
const { t } = useI18n()
const dialogVisible = ref(false)
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -26,7 +28,7 @@ const state = reactive({
scope: '',
client_id: '',
client_secret: '',
redirect_url: '',
redirect_url: getSQLBotAddr(),
token_auth_method: 'basic',
userinfo_auth_method: 'header',
logout_redirect_url: '',
@@ -81,6 +83,15 @@ const validateUrl = (rule, value, callback) => {
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const validateCbUrl = (rule, value, callback) => {
const addr = getSQLBotAddr()
if (value === addr || `${value}/` === addr) {
callback()
}
callback(new Error(t('authentication.callback_domain_name_error')))
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const validateMapping = (rule, value, callback) => {
if (value === null || value === '') {
callback()
@@ -183,7 +194,7 @@ const rule = reactive<FormRules>({
message: t('commons.input_limit', [10, 255]),
trigger: 'blur',
},
{ required: true, validator: validateUrl, trigger: 'blur' },
{ required: true, validator: validateCbUrl, trigger: 'blur' },
],
mapping: [{ required: false, validator: validateMapping, trigger: 'blur' }],
})
@@ -4,6 +4,8 @@ import { ElMessage, ElLoading } from 'element-plus-secondary'
import { useI18n } from 'vue-i18n'
import type { FormInstance, FormRules } from 'element-plus-secondary'
import { request } from '@/utils/request'
import { getSQLBotAddr } from '@/utils/utils'
const { t } = useI18n()
const dialogVisible = ref(false)
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -15,7 +17,7 @@ const state = reactive({
client_id: '',
client_secret: '',
metadata_url: '',
redirect_uri: '',
redirect_uri: getSQLBotAddr(),
realm: '',
scope: '',
mapping: '',
@@ -45,6 +47,15 @@ const validateMapping = (rule, value, callback) => {
}
callback()
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
const validateCbUrl = (rule, value, callback) => {
const addr = getSQLBotAddr()
if (value === addr || `${value}/` === addr) {
callback()
}
callback(new Error(t('authentication.callback_domain_name_error')))
}
const rule = reactive<FormRules>({
client_id: [
{
@@ -84,7 +95,7 @@ const rule = reactive<FormRules>({
message: t('commons.input_limit', [10, 255]),
trigger: 'blur',
},
{ required: true, validator: validateUrl, trigger: 'blur' },
{ required: true, validator: validateCbUrl, trigger: 'blur' },
],
metadata_url: [
{
@@ -90,7 +90,13 @@ const init = (needLoading: boolean) => {
.get(url)
.then((res) => {
if (res) {
infos.value = [...(res as CardInfo[])].filter((item) => item.name !== 'saml2')
const templateArray = ['ldap', 'oidc', 'cas', 'oauth2']
const resultList = [...(res as CardInfo[])].filter((item) => item.name !== 'saml2')
let resultMap = {} as any
resultList.forEach((item: any) => {
resultMap[item.name] = item
})
infos.value = templateArray.map((item: string) => resultMap[item])
showInfos.value = [...infos.value]
}
loading.value = false
@@ -130,14 +136,6 @@ const editInfo = (item: CardInfo) => {
}
}
const validate = (id: any) => {
if (!id) {
ElMessage.error(
`${t('ds.test_connection') + t('report.last_status_fail')}: ${t(
'system.platform_information_first'
)}`
)
return
}
loading.value = true
request
.patch('/system/authentication/status', { type: id, name: '', config: '' })