Skip to content

Commit

Permalink
fix: 密码设置增加配置 TencentBlueKing#238
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri0528 committed Mar 2, 2022
1 parent a08efe7 commit a16dfd3
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 3 deletions.
36 changes: 36 additions & 0 deletions src/pages/src/components/catalog/operation/SetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@
<p class="error-text" v-if="!defaultPassword.password_must_includes.length">{{$t('密码规则不得为空')}}</p>
</div>

<!-- 密码不允许 -->
<div class="info-container">
<div class="auto-freeze-container" style="margin-bottom: 10px;">
<span>{{$t('密码不允许连续')}}</span>
<bk-input
v-model="defaultPassword.password_rult_length"
type="number"
style="width: 120px;margin: 0 8px;"
:class="{ 'king-input': true, error: passwordRuleError }"
@input="validatePasswordRule">
<template slot="append">
<div class="group-text">{{$t('')}}</div>
</template>
</bk-input>
<span>{{$t('出现')}}:</span>
</div>
<p class="error-text" v-show="passwordRuleError">{{$t('不能小于3位,大于8位')}}</p>
<bk-checkbox-group
v-model="defaultPassword.exclude_elements_config"
style="display: flex;height: 19px;margin-top: 10px;">
<bk-checkbox value="keyboard_seq" style="margin-right: 28px;">{{$t('键盘序')}}</bk-checkbox>
<bk-checkbox value="alphabet_seq" style="margin-right: 28px;">{{$t('连续字母序')}}</bk-checkbox>
<bk-checkbox value="num_seq" style="margin-right: 28px;">{{$t('连续数字序')}}</bk-checkbox>
<bk-checkbox value="special_seq" style="margin-right: 28px;">{{$t('连续特殊符号序')}}</bk-checkbox>
<bk-checkbox value="duplicate_char" style="margin-right: 28px;">{{$t('重复字母、数字、特殊符号')}}</bk-checkbox>
</bk-checkbox-group>
</div>

<!-- 密码有效期 -->
<div class="info-container">
<div class="title-container">
Expand Down Expand Up @@ -314,6 +342,8 @@ export default {
// 密码长度是否错误
passwordLengthError: false,
passwordHistoryError: false,
// 密码不允许连续出现
passwordRuleError: false,
// 密码解锁时间是否错误
autoUnlockError: false,
// 未登录自动冻结天数是否错误
Expand Down Expand Up @@ -357,6 +387,7 @@ export default {
return !this.defaultPassword.password_must_includes.length
|| this.passwordLengthError
|| this.passwordHistoryError
|| this.passwordRuleError
|| this.autoUnlockError
|| this.freezeDaysError
|| this.initPasswordError
Expand Down Expand Up @@ -387,6 +418,10 @@ export default {
this.passwordLengthError = this.defaultPassword.password_min_length < 8
|| this.defaultPassword.password_min_length > 32;
},
validatePasswordRule() {
this.passwordRuleError = this.defaultPassword.password_rult_length < 3
|| this.defaultPassword.password_rult_length > 8;
},
// 校验密码重复次数
validatePasswordHistory() {
this.passwordHistoryError = this.defaultPassword.max_password_history.value <= 0;
Expand Down Expand Up @@ -423,6 +458,7 @@ export default {
// 提交前验证是否有错误
validate() {
this.validatePasswordLength();
this.validatePasswordRule();
this.validateAutoUnlock();
this.validateFreezeDays();
this.validateInitPassword();
Expand Down
9 changes: 9 additions & 0 deletions src/pages/src/language/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,13 @@ export default {
蓝鲸用户管理字段: 'Blue Whale User management field',
对应: 'The corresponding',
目录字段: 'Category field',
密码不允许连续: 'Passwords cannot be consecutive',
: 'position',
出现: 'appear',
'不能小于3位,大于8位': 'No less than 3 bits, no more than 8 bits',
键盘序: 'Keyboard sequence',
连续字母序: 'Continuous alphabetic order',
连续数字序: 'Continuous numeric sequence',
连续特殊符号序: 'Continuous special sign order',
'重复字母、数字、特殊符号': 'Repeat letters, numbers, special symbols',
};
9 changes: 9 additions & 0 deletions src/pages/src/language/lang/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,4 +390,13 @@ export default {
蓝鲸用户管理字段: '蓝鲸用户管理字段',
对应: '对应',
目录字段: '目录字段',
密码不允许连续: '密码不允许连续',
: '位',
出现: '出现',
'不能小于3位,大于8位': '不能小于3位,大于8位',
键盘序: '键盘序',
连续字母序: '连续字母序',
连续数字序: '连续数字序',
连续特殊符号序: '连续特殊符号序',
'重复字母、数字、特殊符号': '重复字母、数字、特殊符号',
};
33 changes: 32 additions & 1 deletion src/pages/src/plugins/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ const methods = {
Vue.prototype.$convertPassportRes = function (obj) {
const objectData = {};
const enabledKeys = ['max_password_history', 'freeze_after_days'];
const list = [];
let num = null;
obj.forEach((regionArray) => {
try {
if (enabledKeys.includes(regionArray.key)) {
Expand All @@ -138,19 +140,32 @@ const methods = {
console.warn('数据结构异常', e);
}
});
Object.entries(objectData.exclude_elements_config).forEach((k) => {
list.push(k[0]);
num = k[1];
});
objectData.exclude_elements_config = list;
this.$set(objectData, 'password_rult_length', num);
return objectData;
};

Vue.prototype.$convertPassportInfoArray = function (arr) {
Vue.prototype.$convertPassportInfoArray = function (arr, arr2) {
try {
const arrayData = [];
const num = arr2.password_rult_length;
Object.entries(arr).forEach((regionArray) => {
const key = regionArray[0];
let value = regionArray[1];
let enabled = true;
const obj = {};
if (regionArray[1].value) {
value = regionArray[1].value;
enabled = regionArray[1].enabled;
} else if (key === 'exclude_elements_config') {
Object.entries(value).forEach((k) => {
this.$set(obj, k[1], num);
});
value = obj;
}
arrayData.push({ key, value, enabled });
});
Expand All @@ -165,6 +180,7 @@ const methods = {
const objectData = {};
const enabledKeys = ['max_password_history', 'freeze_after_days'];
Object.entries(obj).forEach((regionArray) => {
console.log('regionArray', regionArray);
Object.entries(regionArray[1]).forEach((regionData) => {
const key = regionData[0];
const value = regionData[1];
Expand All @@ -176,6 +192,9 @@ const methods = {
}
});
});
objectData.exclude_elements_config = [];
this.$set(objectData, 'password_rult_length', 3);
console.log('objectData', objectData);
return objectData;
} catch (e) {
console.warn('数据结构异常', e);
Expand All @@ -196,6 +215,18 @@ const methods = {
}
};

Vue.prototype.$ArrayToObject = function (arr) {
try {
const objectData = {};
arr.forEach((regionObject) => {
console.log('regionObject', regionObject);
});
return objectData;
} catch (e) {
console.warn('参数错误', e);
}
};

// 获取字符串长度,中文为 2 个字符长度
Vue.prototype.$getStringLength = function (string) {
// 匹配所有的中文
Expand Down
2 changes: 1 addition & 1 deletion src/pages/src/views/catalog/operation/LocalAdd.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default {
this.isLoading = true;
await this.$store.dispatch('catalog/ajaxPostPassport', {
id: this.catalogId,
data: this.$convertPassportInfoArray(this.passportInfo),
data: this.$convertPassportInfoArray(this.passportInfo, this.passportInfo),
});
this.$bus.$emit('updateCatalogList');
this.messageSuccess(this.$t('保存成功'));
Expand Down
2 changes: 1 addition & 1 deletion src/pages/src/views/catalog/operation/LocalSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default {
const action = this.passwordHasCreated ? 'catalog/ajaxPutPassport' : 'catalog/ajaxPostPassport';
await this.$store.dispatch(action, {
id: this.catalogInfo.id,
data: this.$convertPassportInfoArray(this.passwordInfo),
data: this.$convertPassportInfoArray(this.passwordInfo, this.passwordInfo),
});
this.handleSaveSuccess();
} catch (e) {
Expand Down

0 comments on commit a16dfd3

Please sign in to comment.