fix(系统设置): 认证设置表单参数校验

This commit is contained in:
shiziyuan9527 2022-11-16 11:23:29 +08:00 committed by 刘瑞斌
parent 5a6299fa4f
commit ad5bccccbc
1 changed files with 44 additions and 71 deletions

View File

@ -82,16 +82,16 @@
<div class="node-line" v-if="form.type === 'CAS'">
<el-row>
<el-col>
<el-form-item label="CAS URL" :rules="requiredRules">
<el-form-item label="CAS URL" :rules="requiredRules" prop="configuration.casUrl">
<el-input v-model="form.configuration.casUrl" placeholder="eg: http://<casurl>"/>
</el-form-item>
<el-form-item label="Login URL" :rules="requiredRules">
<el-form-item label="Login URL" :rules="requiredRules" prop="configuration.loginUrl">
<el-input v-model="form.configuration.loginUrl" placeholder="eg: http://<casurl>/login"/>
</el-form-item>
<el-form-item label="Validate URL" :rules="requiredRules">
<el-form-item label="Validate URL" :rules="requiredRules" prop="configuration.validateUrl">
<el-input v-model="form.configuration.validateUrl" placeholder="eg: http://<casurl>/serviceValidate"/>
</el-form-item>
<el-form-item :rules="requiredRules">
<el-form-item :rules="requiredRules" prop="configuration.redirectUrl">
<template v-slot:label>
Redirect URL
<el-tooltip content="Logout redirect URL: http://<metersphere-endpoint>/sso/callback/cas/logout"
@ -110,7 +110,7 @@
<el-row>
<el-col>
<el-form-item label="Auth Endpoint"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.authUrl">
<el-input v-model="form.configuration.authUrl"
placeholder="eg: http://<keycloak>/auth/realms/<metersphere>/protocol/openid-connect/auth"/>
</el-form-item>
@ -119,7 +119,7 @@
<el-row>
<el-col>
<el-form-item label="Token Endpoint"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.tokenUrl">
<el-input v-model="form.configuration.tokenUrl"
placeholder="eg: http://<keycloak>/auth/realms/<metersphere>/protocol/openid-connect/token"/>
</el-form-item>
@ -128,7 +128,7 @@
<el-row>
<el-col>
<el-form-item label="Userinfo Endpoint"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.userInfoUrl">
<el-input v-model="form.configuration.userInfoUrl"
placeholder="eg: http://<keycloak>/auth/realms/<metersphere>/protocol/openid-connect/userinfo"/>
</el-form-item>
@ -136,8 +136,7 @@
</el-row>
<el-row>
<el-col>
<el-form-item
:rules="requiredRules">
<el-form-item :rules="requiredRules" prop="configuration.logoutUrl">
<template v-slot:label>
Logout Endpoint
<el-tooltip content="Logout redirect URL: http://<metersphere-endpoint>/sso/callback/logout"
@ -153,7 +152,7 @@
</el-row>
<el-row>
<el-col>
<el-form-item label="Client ID"
<el-form-item label="Client ID" prop="configuration.clientId"
:rules="requiredRules">
<el-input v-model="form.configuration.clientId" placeholder="eg: metersphere"/>
</el-form-item>
@ -161,7 +160,7 @@
</el-row>
<el-row>
<el-col>
<el-form-item label="Redirect URL"
<el-form-item label="Redirect URL" prop="configuration.redirectUrl"
:rules="requiredRules">
<el-input v-model="form.configuration.redirectUrl"
placeholder="eg: http://<metersphere-endpoint>/sso/callback or http://<metersphere-endpoint>/sso/callback/${authId}"/>
@ -171,7 +170,7 @@
<el-row>
<el-col>
<el-form-item label="Secret"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.secret">
<el-input type="password" v-model="form.configuration.secret" show-password autocomplete="new-password"
placeholder="OIDC client secret"/>
</el-form-item>
@ -181,7 +180,7 @@
<div class="node-line" v-if="form.type === 'OAuth2'">
<el-row>
<el-col>
<el-form-item label="Auth Endpoint"
<el-form-item label="Auth Endpoint" prop="configuration.authUrl"
:rules="requiredRules">
<el-input v-model="form.configuration.authUrl"
placeholder="eg: http://example.com/login/oauth/authorize"/>
@ -191,7 +190,7 @@
<el-row>
<el-col>
<el-form-item label="Token Endpoint"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.tokenUrl">
<el-input v-model="form.configuration.tokenUrl"
placeholder="eg: https://example.com/login/oauth/access_token"/>
</el-form-item>
@ -200,7 +199,7 @@
<el-row>
<el-col>
<el-form-item label="Userinfo Endpoint"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.userInfoUrl">
<el-input v-model="form.configuration.userInfoUrl"
placeholder="eg: https://example.com/user"/>
</el-form-item>
@ -209,7 +208,7 @@
<el-row>
<el-col>
<el-form-item label="Redirect URL"
:rules="requiredRules">
:rules="requiredRules" prop="configuration.redirectUrl">
<el-input v-model="form.configuration.redirectUrl"
placeholder="eg: http://<metersphere-endpoint>/sso/callback/oauth2"/>
</el-form-item>
@ -217,7 +216,7 @@
</el-row>
<el-row>
<el-col>
<el-form-item label="Client ID"
<el-form-item label="Client ID" prop="configuration.clientId"
:rules="requiredRules">
<el-input v-model="form.configuration.clientId" placeholder="eg: metersphere"/>
</el-form-item>
@ -225,7 +224,7 @@
</el-row>
<el-row>
<el-col>
<el-form-item label="Secret"
<el-form-item label="Secret" prop="configuration.secret"
:rules="requiredRules">
<el-input type="password" v-model="form.configuration.secret" show-password autocomplete="new-password"
placeholder="oauth2 client secret"/>
@ -234,14 +233,14 @@
</el-row>
<el-row>
<el-col>
<el-form-item label="Scope" :rules="requiredRules">
<el-form-item label="Scope" :rules="requiredRules" prop="configuration.scope">
<el-input v-model="form.configuration.scope"/>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col>
<el-form-item label="Property Mapping" :rules="requiredRules">
<el-form-item label="Property Mapping" :rules="requiredRules" prop="configuration.mapping">
<el-input v-model="form.configuration.mapping"
:placeholder="mappingTip"/>
</el-form-item>
@ -298,10 +297,10 @@ export default {
pageSize: 10,
total: 0,
form: {configuration: {}},
requiredRules: [{required: true, message: this.$t('test_resource_pool.fill_the_data'), trigger: 'blur'}],
requiredRules: [ {required: true, message: this.$t('test_resource_pool.fill_the_data'), trigger: ['blur']}],
rule: {
name: [
{required: true, message: this.$t('test_resource_pool.input_pool_name'), trigger: 'blur'},
{required: true, message: this.$t('commons.input_name'), trigger: 'blur'},
{min: 2, max: 20, message: this.$t('commons.input_limit', [2, 20]), trigger: 'blur'},
{
required: true,
@ -381,30 +380,15 @@ export default {
this.$info(this.$t('commons.delete_cancel'));
});
},
changeAuthType(type) {
},
validateInfo() {
let resultValidate = {validate: true, msg: this.$t('test_resource_pool.fill_the_data')};
let info = this.form.configuration;
for (let key in info) {
// Oauth2 logoutUrl
if (this.form.type === 'OAuth2' && key === 'logoutUrl') {
continue;
changeAuthType() {
this.form.configuration = {};
if (this.$refs.authSourceForm) {
this.$refs.authSourceForm.clearValidate();
}
if (info[key] !== '0' && !info[key]) {
resultValidate.validate = false;
return resultValidate;
}
}
return resultValidate;
},
createAuthSource() {
this.$refs.authSourceForm.validate(valid => {
if (valid) {
let vri = this.validateInfo();
if (vri.validate) {
let model = JSON.parse(JSON.stringify(this.form));
model.configuration = JSON.stringify(model.configuration);
this.dialogLoading = addAuth(model)
@ -416,11 +400,6 @@ export default {
this.dialogVisible = false,
this.initTableData());
});
} else {
this.$warning(vri.msg);
return false;
}
} else {
return false;
}
@ -431,8 +410,6 @@ export default {
if (!valid) {
return false;
}
let vri = this.validateInfo();
if (vri.validate) {
let model = JSON.parse(JSON.stringify(this.form));
model.configuration = JSON.stringify(model.configuration);
this.dialogLoading = updateAuth(model)
@ -441,10 +418,6 @@ export default {
this.dialogVisible = false;
this.initTableData();
});
} else {
this.$warning(vri.msg);
return false;
}
});
},
},