Skip to content

Commit

Permalink
Merge pull request #349 from yuri0528/dev-login
Browse files Browse the repository at this point in the history
fix: 密码规则校验
  • Loading branch information
IMBlues authored Apr 7, 2022
2 parents e5efe78 + cb2fee5 commit f26358c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
32 changes: 30 additions & 2 deletions src/pages/src/components/catalog/operation/SetPassword.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
type="number"
style="width: 120px;margin: 0 8px;"
:class="{ 'king-input': true, error: passwordRuleError }"
@input="validatePasswordRule">
@change="handleChange">
<template slot="append">
<div class="group-text">{{$t('位')}}</div>
</template>
Expand All @@ -81,6 +81,7 @@
<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>
<p class="error-text" v-show="passwordConfigError">{{$t('密码规则不得为空')}}</p>
</div>

<!-- 密码有效期 -->
Expand Down Expand Up @@ -344,6 +345,7 @@ export default {
passwordHistoryError: false,
// 密码不允许连续出现
passwordRuleError: false,
passwordConfigError: false,
// 密码解锁时间是否错误
autoUnlockError: false,
// 未登录自动冻结天数是否错误
Expand Down Expand Up @@ -388,6 +390,7 @@ export default {
|| this.passwordLengthError
|| this.passwordHistoryError
|| this.passwordRuleError
|| this.passwordConfigError
|| this.autoUnlockError
|| this.freezeDaysError
|| this.initPasswordError
Expand All @@ -398,13 +401,38 @@ export default {
passportInfo() {
this.init();
},
'defaultPassword.exclude_elements_config'(newVal) {
if (newVal.length) {
this.validatePasswordRule();
this.passwordConfigError = false;
} else if (!newVal.length && this.defaultPassword.password_rult_length) {
this.passwordConfigError = true;
} else {
this.passwordRuleError = false;
this.passwordConfigError = false;
}
},
},
created() {
if (this.passportInfo) {
this.init();
}
},
methods: {
handleChange(value) {
if (value !== '') {
this.validatePasswordRule();
if (!this.defaultPassword.exclude_elements_config.length) {
this.passwordConfigError = true;
}
} else if (this.defaultPassword.exclude_elements_config.length) {
this.passwordRuleError = true;
this.passwordConfigError = false;
} else {
this.passwordRuleError = false;
this.passwordConfigError = false;
}
},
init() {
// 监听密码规则的变化去验证初始密码
this.$watch(() => {
Expand Down Expand Up @@ -475,7 +503,7 @@ export default {
},
// 保存
saveInfo() {
this.validate() && this.$emit('savePassport', this.passwordRuleError);
this.validate() && this.$emit('savePassport');
},
// 展开或隐藏邮件模板
toggleEmailTemplate() {
Expand Down
16 changes: 10 additions & 6 deletions src/pages/src/plugins/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,18 @@ const methods = {
let value = regionArray[1];
let enabled = true;
const obj = {};
if (regionArray[1].value) {
if (regionArray[1] && 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;
if (value.length) {
Object.entries(value).forEach((k) => {
this.$set(obj, k[1], num);
});
value = obj;
}
} else if (key === 'password_rult_length') {
if (!value) value = '';
}
arrayData.push({ key, value, enabled });
});
Expand All @@ -192,7 +196,7 @@ const methods = {
});
});
objectData.exclude_elements_config = [];
this.$set(objectData, 'password_rult_length', 3);
this.$set(objectData, 'password_rult_length', '');
return objectData;
} catch (e) {
console.warn('数据结构异常', e);
Expand Down
8 changes: 1 addition & 7 deletions src/pages/src/views/catalog/operation/LocalSet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,9 @@ export default {
this.isLoading = false;
}
},
async handleSavePassport(state) {
async handleSavePassport() {
try {
this.isLoading = true;
console.log(state);
if (this.passwordInfo.password_rult_length === null) {
this.passwordInfo.password_rult_length = '';
} else {
state = true;
}
const action = this.passwordHasCreated ? 'catalog/ajaxPutPassport' : 'catalog/ajaxPostPassport';
await this.$store.dispatch(action, {
id: this.catalogInfo.id,
Expand Down

0 comments on commit f26358c

Please sign in to comment.