Skip to content

Commit 2ff3e10

Browse files
perf: i18n Optimization for Third-Party Authentication Validation
1 parent f105a53 commit 2ff3e10

File tree

11 files changed

+65
-15
lines changed

11 files changed

+65
-15
lines changed

backend/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@
114114
},
115115
"i18n_excel_import": {
116116
"col_num_not_match": "Number of columns in Excel does not match"
117+
},
118+
"i18n_authentication": {
119+
"record_not_exist": "{msg} record does not exist. Please save it first!"
117120
}
118121
}

backend/locales/ko-KR.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@
114114
},
115115
"i18n_excel_import": {
116116
"col_num_not_match": "Excel 열 개수가 일치하지 않습니다"
117+
},
118+
"i18n_authentication": {
119+
"record_not_exist": "{msg} 기록이 존재하지 않습니다. 먼저 저장해 주세요!"
117120
}
118121
}

backend/locales/zh-CN.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,8 @@
114114
},
115115
"i18n_excel_import": {
116116
"col_num_not_match": "EXCEL列数量不匹配"
117+
},
118+
"i18n_authentication": {
119+
"record_not_exist": "{msg} 记录不存在,请先保存!"
117120
}
118121
}

frontend/src/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@
732732
"valid": "Valid",
733733
"cas_settings": "CAS Settings",
734734
"callback_domain_name": "Callback Domain",
735+
"callback_domain_name_error": "Callback URL must match the current access domain",
735736
"field_mapping": "User Attribute Mapping",
736737
"field_mapping_placeholder": "Example: {'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
737738
"incorrect_please_re_enter": "Incorrect format, please re-enter",

frontend/src/i18n/ko-KR.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@
732732
"valid": "유효함",
733733
"cas_settings": "CAS 설정",
734734
"callback_domain_name": "콜백 도메인",
735+
"callback_domain_name_error": "콜백 URL은 현재 접속 도메인과 일치해야 합니다",
735736
"field_mapping": "사용자 속성 매핑",
736737
"field_mapping_placeholder": "예: {'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
737738
"incorrect_please_re_enter": "형식이 잘못되었습니다. 다시 입력해 주세요",

frontend/src/i18n/zh-CN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@
732732
"valid": "有效",
733733
"cas_settings": "CAS 设置",
734734
"callback_domain_name": "回调地址",
735+
"callback_domain_name_error": "回调地址必须是当前访问域名",
735736
"field_mapping": "用户属性映射",
736737
"field_mapping_placeholder": "例如:{'{'}\"account\": \"saml2Account\", \"name\": \"saml2Name\", \"email\": \"email\"{'}'}",
737738
"incorrect_please_re_enter": "格式错误,请重新填写",

frontend/src/utils/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,11 @@ export function isMobile() {
255255
) && !isTablet()
256256
)
257257
}
258+
259+
export const getSQLBotAddr = (portEnd?: boolean) => {
260+
const addr = location.origin + location.pathname
261+
if (!portEnd || !addr.endsWith('/')) {
262+
return addr
263+
}
264+
return addr.substring(0, addr.length - 1)
265+
}

frontend/src/views/system/authentication/CasEditor.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ElMessage, ElLoading } from 'element-plus-secondary'
44
import { useI18n } from 'vue-i18n'
55
import type { FormInstance, FormRules } from 'element-plus-secondary'
66
import { request } from '@/utils/request'
7+
import { getSQLBotAddr } from '@/utils/utils'
78
const { t } = useI18n()
89
const dialogVisible = ref(false)
910
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -17,7 +18,7 @@ interface CasForm {
1718
const state = reactive({
1819
form: reactive<CasForm>({
1920
idpUri: '',
20-
casCallbackDomain: '',
21+
casCallbackDomain: getSQLBotAddr(),
2122
mapping: '',
2223
}),
2324
})
@@ -33,6 +34,15 @@ const validateUrl = (rule, value, callback) => {
3334
}
3435
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3536
// @ts-expect-error
37+
const validateCbUrl = (rule, value, callback) => {
38+
const addr = getSQLBotAddr()
39+
if (value === addr || `${value}/` === addr) {
40+
callback()
41+
}
42+
callback(new Error(t('authentication.callback_domain_name_error')))
43+
}
44+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
45+
// @ts-expect-error
3646
const validateMapping = (rule, value, callback) => {
3747
if (!value) {
3848
callback()
@@ -76,7 +86,7 @@ const rule = reactive<FormRules>({
7686
message: t('commons.input_limit', [10, 255]),
7787
trigger: 'blur',
7888
},
79-
{ required: true, validator: validateUrl, trigger: 'blur' },
89+
{ required: true, validator: validateCbUrl, trigger: 'blur' },
8090
],
8191
mapping: [{ required: false, validator: validateMapping, trigger: 'blur' }],
8292
})

frontend/src/views/system/authentication/Oauth2Editor.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
ElSelect,
1212
} from 'element-plus-secondary'
1313
import { request } from '@/utils/request'
14+
import { getSQLBotAddr } from '@/utils/utils'
15+
1416
const { t } = useI18n()
1517
const dialogVisible = ref(false)
1618
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -26,7 +28,7 @@ const state = reactive({
2628
scope: '',
2729
client_id: '',
2830
client_secret: '',
29-
redirect_url: '',
31+
redirect_url: getSQLBotAddr(),
3032
token_auth_method: 'basic',
3133
userinfo_auth_method: 'header',
3234
logout_redirect_url: '',
@@ -81,6 +83,15 @@ const validateUrl = (rule, value, callback) => {
8183
}
8284
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
8385
// @ts-expect-error
86+
const validateCbUrl = (rule, value, callback) => {
87+
const addr = getSQLBotAddr()
88+
if (value === addr || `${value}/` === addr) {
89+
callback()
90+
}
91+
callback(new Error(t('authentication.callback_domain_name_error')))
92+
}
93+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
94+
// @ts-expect-error
8495
const validateMapping = (rule, value, callback) => {
8596
if (value === null || value === '') {
8697
callback()
@@ -183,7 +194,7 @@ const rule = reactive<FormRules>({
183194
message: t('commons.input_limit', [10, 255]),
184195
trigger: 'blur',
185196
},
186-
{ required: true, validator: validateUrl, trigger: 'blur' },
197+
{ required: true, validator: validateCbUrl, trigger: 'blur' },
187198
],
188199
mapping: [{ required: false, validator: validateMapping, trigger: 'blur' }],
189200
})

frontend/src/views/system/authentication/OidcEditor.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { ElMessage, ElLoading } from 'element-plus-secondary'
44
import { useI18n } from 'vue-i18n'
55
import type { FormInstance, FormRules } from 'element-plus-secondary'
66
import { request } from '@/utils/request'
7+
import { getSQLBotAddr } from '@/utils/utils'
8+
79
const { t } = useI18n()
810
const dialogVisible = ref(false)
911
const loadingInstance = ref<ReturnType<typeof ElLoading.service> | null>(null)
@@ -15,7 +17,7 @@ const state = reactive({
1517
client_id: '',
1618
client_secret: '',
1719
metadata_url: '',
18-
redirect_uri: '',
20+
redirect_uri: getSQLBotAddr(),
1921
realm: '',
2022
scope: '',
2123
mapping: '',
@@ -45,6 +47,15 @@ const validateMapping = (rule, value, callback) => {
4547
}
4648
callback()
4749
}
50+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
51+
// @ts-expect-error
52+
const validateCbUrl = (rule, value, callback) => {
53+
const addr = getSQLBotAddr()
54+
if (value === addr || `${value}/` === addr) {
55+
callback()
56+
}
57+
callback(new Error(t('authentication.callback_domain_name_error')))
58+
}
4859
const rule = reactive<FormRules>({
4960
client_id: [
5061
{
@@ -84,7 +95,7 @@ const rule = reactive<FormRules>({
8495
message: t('commons.input_limit', [10, 255]),
8596
trigger: 'blur',
8697
},
87-
{ required: true, validator: validateUrl, trigger: 'blur' },
98+
{ required: true, validator: validateCbUrl, trigger: 'blur' },
8899
],
89100
metadata_url: [
90101
{

0 commit comments

Comments
 (0)