Skip to content

Commit

Permalink
feature: ldap地址格式校验 #436
Browse files Browse the repository at this point in the history
  • Loading branch information
v_yutyi authored and EmilyMei committed May 20, 2022
1 parent a26730c commit 79f5968
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/pages/src/components/catalog/operation/CommonInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
:style="{ width: inputWidth + 'px' }"
:class="{ 'king-input': true, error: error }"
:disabled="disabled"
:placeholder="placeholder"
@input="handleInput">
<template v-if="append" slot="append">
<div class="group-text">{{append}}</div>
</template>
</bk-input>
<p v-show="error" class="error-text">{{errorText || $t('请输入') + title}}</p>
<p v-show="!regError" class="error-text">{{$t('请输入合法的ldap地址')}}</p>
<p v-if="description" class="description">{{description}}</p>
</div>
</template>
Expand Down Expand Up @@ -102,12 +104,22 @@ export default {
type: String,
default: '',
},
placeholder: {
type: String,
default: '',
},
},
data() {
return {
error: false,
regError: true,
};
},
watch: {
'info.connection_url'() {
this.regError = true;
},
},
mounted() {
this.inputBus.$on('validateCatalogInfo', () => {
// 提交时 trim
Expand All @@ -117,6 +129,7 @@ export default {
this.info[this.keyword] = value.trim();
}
this.validate();
this.regUrl();
});
},
methods: {
Expand Down Expand Up @@ -159,6 +172,22 @@ export default {
}
}
},
regUrl() {
const key = this.keyword;
const value = this.info[this.keyword];
if (key === 'connection_url') {
const url = value.split('://')[0];
this.$emit('updateUrl', url);
// IP | IP + 端口号
const ipReg = new RegExp(/^ldap(s)?:\/\/(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5]):([0-9]|[1-9]\d{1,3})$/);
// 域名 | 域名 + 端口号
const reg = new RegExp(/^ldap(s)?:\/\/(([a-zA-Z0-9]([-a-zA-Z0-9])*){1,62}\.)+[a-zA-Z]{2,62}(:([0-9]|[1-9]\d{1,3}))?$/);
this.regError = reg.test(value) || ipReg.test(value);
if (this.regError === false) {
this.$emit('hasError');
}
}
},
},
};
</script>
Expand Down
26 changes: 24 additions & 2 deletions src/pages/src/components/catalog/operation/SetConnection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,23 @@
:input-bus="inputBus"
:title="$t('连接地址')"
:is-need="true"
@hasError="handleHasError" />
:placeholder="`${$t('例如')}:ldap://127.0.0.1:389`"
@hasError="handleHasError"
@updateUrl="updateUrl" />

<!-- SSL加密方式 -->
<div class="info-container">
<div class="title-container">
<h4 class="title">{{$t('SSL加密方式')}}</h4>
</div>
<bk-select v-model="defaultConnection.ssl_encryption" :clearable="false" style="width: 360px;">
<bk-select
v-model="defaultConnection.ssl_encryption"
:clearable="false"
style="width: 360px;"
@toggle="toggleSelect">
<bk-option v-for="option in sslEncryptionChoices" :key="option" :id="option" :name="option"></bk-option>
</bk-select>
<p v-show="sslError" class="error-text">{{$t('请选择正确的加密方式')}}</p>
</div>

<!-- 超时设置 -->
Expand Down Expand Up @@ -155,6 +162,7 @@ export default {
// 表单验证是否有错误
hasError: false,
inputBus: new Vue(),
sslError: false,
};
},
computed: {
Expand Down Expand Up @@ -200,6 +208,20 @@ export default {
});
return false;
},
updateUrl(val) {
if (val === 'ldaps' && this.defaultConnection.ssl_encryption === '无') {
this.sslError = true;
this.hasError = true;
} else if (val === 'ldap' && this.defaultConnection.ssl_encryption === 'SSL') {
this.sslError = true;
this.hasError = true;
} else {
this.sslError = false;
}
},
toggleSelect() {
this.sslError = false;
},
},
};
</script>
Expand Down
3 changes: 3 additions & 0 deletions src/pages/src/language/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,7 @@ export default {
被删除: 'deleted',
员工: 'employees',
组长: 'group leader',
请输入合法的ldap地址: 'Please enter a valid LDAP address',
例如: 'For example',
请选择正确的加密方式: 'Select the correct encryption mode',
};
3 changes: 3 additions & 0 deletions src/pages/src/language/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,4 +410,7 @@ export default {
被删除: '被删除',
员工: '员工',
组长: '组长',
请输入合法的ldap地址: '请输入合法的ldap地址',
例如: '例如',
请选择正确的加密方式: '请选择正确的加密方式',
};

0 comments on commit 79f5968

Please sign in to comment.