Skip to content

Commit

Permalink
fix(frontend): 密码存量接口功能回退 #1356 (#1357)
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves authored Oct 11, 2023
1 parent 8274791 commit fccf0e2
Show file tree
Hide file tree
Showing 7 changed files with 735 additions and 711 deletions.
38 changes: 28 additions & 10 deletions dbm-ui/frontend/src/services/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,39 @@ interface MysqlAdminPasswordResultItem {
port: number
}

/**
* 更新密码策略
*/
export interface PasswordPolicyParams {
account_type: string,
policy: PasswordPolicy
}

/**
* 查询公钥参数
*/
export interface RSAPublicKeyParams {
names: string[]
}

/**
* 公钥信息
*/
export interface RSAPublicKey {
content: string,
description: string,
name: string,
}

/**
* 查询密码安全策略
*/
export const getPasswordPolicy = () => http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/');
export const getPasswordPolicy = (accountType: string) => http.get<PasswordPolicy>('/apis/conf/password_policy/get_password_policy/', { account_type: accountType });

/**
* 更新密码安全策略
*/
export const updatePasswordPolicy = (params: PasswordPolicy) => http.post('/apis/conf/password_policy/update_password_policy/', params);
export const updatePasswordPolicy = (params: PasswordPolicyParams) => http.post<PasswordPolicyParams>('/apis/conf/password_policy/update_password_policy/', params);

/**
* 查询随机化周期
Expand Down Expand Up @@ -125,18 +149,12 @@ export const queryMysqlAdminPassword = (params: {
/**
* 获取公钥列表
*/
export const getRSAPublicKeys = (params: {
names: string[]
}) => http.post<{
content: string,
description: string,
name: string,
}[]>('/apis/core/encrypt/fetch_public_keys/', params);
export const getRSAPublicKeys = (params: RSAPublicKeyParams) => http.post<RSAPublicKey[]>('/apis/core/rsa/fetch_public_keys/', params);

/**
* 校验密码强度
*/
export const verifyPasswordStrength = (password: string) => http.post<PasswordStrength>('/apis/conf/password_policy/verify_password_strength/', { password });
export const verifyPasswordStrength = (bizId: number, password: string, accountType?: AccountTypesValues) => http.post<PasswordStrength>(`/apis/mysql/bizs/${bizId}/permission/account/verify_password_strength/`, { password, account_type: accountType });

/**
* 查询账号规则列表
Expand Down
31 changes: 19 additions & 12 deletions dbm-ui/frontend/src/services/types/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,25 @@ export interface PasswordStrengthVerifyInfo {

// 密码策略
export interface PasswordPolicy {
id: number,
name: string,
rule: {
include_rule: PasswordPolicyIncludeRule
exclude_continuous_rule: PasswordPolicyExcludeContinuousRule,
max_length: number,
min_length: number,
},
creator?: string,
create_time?: string,
operator?: string,
update_time?: string
follow: PasswordPolicyFollow,
lowercase: boolean,
max_length: number,
min_length: number,
numbers: boolean,
symbols: boolean,
uppercase: boolean
}

/**
* 密码策略 follow
*/
export interface PasswordPolicyFollow {
limit: number,
letters: boolean,
numbers: boolean,
repeats: boolean,
symbols: boolean,
keyboards: boolean
}

// 密码策略 include_rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@
}

type PasswordPolicy = ServiceReturnType<typeof getPasswordPolicy>;
type IncludeRule = PasswordPolicy['rule']['include_rule']
type ExcludeContinuousRule = PasswordPolicy['rule']['exclude_continuous_rule']
type IncludeRule = PasswordPolicy
type ExcludeContinuousRule = PasswordPolicy['follow']
type PasswordStrength = ServiceReturnType<typeof verifyPasswordStrength>;
type PasswordStrengthVerifyInfo = PasswordStrength['password_verify_info']

Expand Down Expand Up @@ -183,7 +183,7 @@
* 获取公钥
*/
function fetchRSAPublicKeys() {
getRSAPublicKeys({ names: ['password'] })
getRSAPublicKeys({ names: ['mysql'] })
.then((res) => {
state.publicKey = res[0]?.content || '';
});
Expand Down Expand Up @@ -219,7 +219,7 @@
* 远程校验密码是否符合要求
*/
function verifyPassword() {
return verifyPasswordStrength(getEncyptPassword())
return verifyPasswordStrength(globalbizsStore.currentBizId, getEncyptPassword())
.then((res) => {
passwordState.validate = res;
return res.is_strength;
Expand All @@ -230,21 +230,20 @@
* 获取密码安全策略
*/
function fetchPasswordPolicy() {
getPasswordPolicy()
getPasswordPolicy('mysql')
.then((res) => {
const {
min_length: minLength,
max_length: maxLength,
include_rule: includeRule,
exclude_continuous_rule: excludeContinuousRule,
} = res.rule;
follow,
} = res;
passwordState.strength = [{
keys: ['min_length_valid', 'max_length_valid'],
text: t('密码长度为_min_max', [minLength, maxLength]),
}];
// 常规提示
for (const key of passwordState.keys) {
if (includeRule[key as keyof IncludeRule]) {
if (res[key as keyof IncludeRule]) {
passwordState.strength.push({
keys: [`${key}_valid`],
text: t(PASSWORD_POLICY[key as PasswordPolicyKeys]),
Expand All @@ -253,17 +252,17 @@
}

// 重复提示
if (excludeContinuousRule.repeats) {
if (follow.repeats) {
passwordState.strength.push({
keys: ['repeats_valid'],
text: t('不能连续重复n位字母_数字_特殊符号', { n: excludeContinuousRule.limit }),
text: t('不能连续重复n位字母_数字_特殊符号', { n: follow.limit }),
});
}

// 特殊提示(键盘序、字符序、数字序等)
const special = passwordState.followKeys.reduce((values: StrengthItem[], key: string) => {
const valueKey = key.replace('follow_', '') as keyof ExcludeContinuousRule;
if (excludeContinuousRule[valueKey]) {
if (res.follow[valueKey]) {
values.push({
keys: [`${key}_valid`],
text: t(PASSWORD_POLICY[key as PasswordPolicyKeys]),
Expand Down
47 changes: 22 additions & 25 deletions dbm-ui/frontend/src/views/password-policy/PasswordPolicy.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@
:label="t('密码必须包含')"
required>
<BkCheckbox
v-model="formData.include_rule.lowercase"
v-model="formData.lowercase"
:false-label="false">
{{ t('小写字母') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.uppercase"
v-model="formData.uppercase"
:false-label="false">
{{ t('大写字母') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.numbers"
v-model="formData.numbers"
:false-label="false">
{{ t('数字') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.include_rule.symbols"
v-model="formData.symbols"
:false-label="false">
{{ t('特殊字符_除空格外') }}
</BkCheckbox>
Expand All @@ -65,33 +65,33 @@
class="password-policy-text mr-8"
style="padding: 0;">N = </span>
<BkInput
v-model="formData.exclude_continuous_rule.limit"
v-model="formData.follow.limit"
class="password-policy-number"
:min="3"
type="number" />
</p>
<BkCheckbox
v-model="formData.exclude_continuous_rule.keyboards"
v-model="formData.follow.keyboards"
:false-label="false">
{{ t('键盘序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.letters"
v-model="formData.follow.letters"
:false-label="false">
{{ t('字母序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.numbers"
v-model="formData.follow.numbers"
:false-label="false">
{{ t('数字序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.symbols"
v-model="formData.follow.symbols"
:false-label="false">
{{ t('连续特殊符号序') }}
</BkCheckbox>
<BkCheckbox
v-model="formData.exclude_continuous_rule.repeats"
v-model="formData.follow.repeats"
:false-label="false">
{{ t('重复字母_数字_特殊符号') }}
</BkCheckbox>
Expand Down Expand Up @@ -127,25 +127,24 @@
import { useInfo } from '@hooks';

const initData = () => ({
max_length: 32,
min_length: 8,
include_rule: {
lowercase: true,
numbers: true,
symbols: true,
uppercase: true,
},
exclude_continuous_rule: {
follow: {
keyboards: false,
letters: false,
limit: 3,
numbers: false,
repeats: false,
symbols: false,
},
lowercase: true,
max_length: 32,
min_length: 8,
numbers: true,
symbols: true,
uppercase: true,
});

const { t } = useI18n();
const accountType = 'mysql';

const passwordPolicyData = {
id: 0,
Expand All @@ -158,11 +157,9 @@

const fetchPasswordPolicy = () => {
isLoading.value = true;
getPasswordPolicy()
getPasswordPolicy(accountType)
.then((passwordPolicy) => {
passwordPolicyData.id = passwordPolicy.id;
passwordPolicyData.name = passwordPolicy.name;
Object.assign(formData, passwordPolicy.rule);
Object.assign(formData, passwordPolicy);
})
.finally(() => {
isLoading.value = false;
Expand All @@ -185,8 +182,8 @@
const handleSubmit = (message = t('保存成功')) => {
isSubmitting.value = true;
updatePasswordPolicy({
...passwordPolicyData,
rule: formData,
account_type: accountType,
policy: formData,
})
.then(() => {
Message({
Expand Down
Loading

0 comments on commit fccf0e2

Please sign in to comment.