Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 765cecd

Browse files
committed
新增 修改密码强制安全策略
1 parent 308f6d3 commit 765cecd

File tree

2 files changed

+117
-100
lines changed

2 files changed

+117
-100
lines changed

src/app/views/UserDetail.vue

Lines changed: 113 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -64,66 +64,8 @@
6464
</el-col>
6565
</el-row>
6666
<el-row :gutter="20">
67-
<el-col :md="16" :offset="0">
68-
<Panel>
69-
<template #title>用户名</template>
70-
<template #default>
71-
<div class="sub-title row-mt">
72-
<p class="sub-title-title">更改用户名</p>
73-
<p class="sub-title-info">支持中文和字母,长度为 2 到 18 个文字</p>
74-
</div>
75-
<el-input
76-
size="small"
77-
placeholder="保持原值"
78-
v-model="userData.userName"
79-
:readonly="readonly.a"
80-
@focus="() => (readonly.a = false)"
81-
autocomplete="off"
82-
></el-input>
83-
<div style="text-align: right">
84-
<el-button size="small" class="row-mt" @click="update(1)">更新用户名</el-button>
85-
</div>
86-
</template>
87-
</Panel>
88-
<Panel>
89-
<template #title>访问密码</template>
90-
<template #default>
91-
<div class="sub-title row-mt">
92-
<p class="sub-title-title">新密码</p>
93-
<p class="sub-title-info">长度必须 6 到 18 位,尽可能包含字母数字加符号组合方式</p>
94-
</div>
95-
<el-input
96-
size="small"
97-
type="password"
98-
v-model="userData.passWord"
99-
autocomplete="off"
100-
placeholder="保持原值"
101-
:readonly="readonly.b"
102-
@focus="() => (readonly.b = false)"
103-
>
104-
</el-input>
105-
<div class="sub-title row-mt">
106-
<p class="sub-title-title">确认新密码</p>
107-
<p class="sub-title-info">为防止新密码误输入,您必须确认一次新密码</p>
108-
</div>
109-
<el-input
110-
size="small"
111-
type="password"
112-
v-model="userData.passWord2"
113-
placeholder="保持原值"
114-
:readonly="readonly.c"
115-
@focus="() => (readonly.c = false)"
116-
autocomplete="off"
117-
>
118-
</el-input>
119-
<div style="text-align: right">
120-
<el-button size="small" class="row-mt" @click="update(2)">更新密码</el-button>
121-
</div>
122-
</template>
123-
</Panel>
124-
</el-col>
12567
<el-col :md="8" :offset="0">
126-
<Panel>
68+
<Panel style="height: 300px">
12769
<template #title>注意事项</template>
12870
<template #default>
12971
<div class="sub-title">
@@ -146,7 +88,79 @@
14688
</div>
14789
</template>
14890
</Panel>
149-
<Panel>
91+
</el-col>
92+
<el-col :md="8" :offset="0">
93+
<!-- <Panel>
94+
<template #title>用户名</template>
95+
<template #default>
96+
<div class="sub-title row-mt">
97+
<p class="sub-title-title require-field">更改用户名</p>
98+
<p class="sub-title-info">支持中文和字母,长度为 2 到 18 个文字</p>
99+
</div>
100+
<el-input
101+
size="small"
102+
placeholder="保持原值"
103+
v-model="userData.userName"
104+
:readonly="readonly.a"
105+
@focus="() => (readonly.a = false)"
106+
autocomplete="off"
107+
></el-input>
108+
<div style="text-align: right">
109+
<el-button size="small" class="row-mt" @click="update(1)" type="danger" plain
110+
>更新用户名</el-button
111+
>
112+
</div>
113+
</template>
114+
</Panel> -->
115+
<Panel style="height: 300px">
116+
<template #title>更新密码</template>
117+
<template #default>
118+
<el-form
119+
:model="userData"
120+
:rules="rules"
121+
label-position="top"
122+
size="small"
123+
ref="ruleFormRef"
124+
>
125+
<el-form-item label="新密码" prop="passWord" required>
126+
<el-input
127+
size="small"
128+
type="password"
129+
v-model="userData.passWord"
130+
autocomplete="off"
131+
:readonly="readonly.b"
132+
placeholder="长度必须 12 到 24 位,尽可能包含字母数字加符号组合方式"
133+
@focus="() => (readonly.b = false)"
134+
>
135+
</el-input>
136+
</el-form-item>
137+
138+
<el-form-item label="确认新密码" prop="passWord2" required>
139+
<el-input
140+
size="small"
141+
type="password"
142+
v-model="userData.passWord2"
143+
placeholder="保持原值"
144+
:readonly="readonly.c"
145+
@focus="() => (readonly.c = false)"
146+
autocomplete="off"
147+
>
148+
</el-input>
149+
</el-form-item>
150+
<div style="text-align: right">
151+
<el-form-item>
152+
<el-button size="small" type="danger" plain class="row-mt" @click="update(2)">
153+
更新密码
154+
</el-button>
155+
</el-form-item>
156+
</div>
157+
</el-form>
158+
</template>
159+
</Panel>
160+
</el-col>
161+
162+
<el-col :md="8" :offset="0">
163+
<Panel style="height: 300px">
150164
<template #title>API 接口密钥</template>
151165
<template #default>
152166
<div class="sub-title row-mt">
@@ -210,6 +224,10 @@ export default {
210224
api: {
211225
enable: false,
212226
key: ""
227+
},
228+
rules: {
229+
passWord: [{ validator: this.validatePassword, trigger: "blur" }],
230+
passWord2: [{ validator: this.validatePassword, trigger: "blur" }]
213231
}
214232
};
215233
},
@@ -221,45 +239,31 @@ export default {
221239
222240
async mounted() {},
223241
methods: {
224-
async update(type) {
225-
await this.$confirm("确定要更改此信息吗?", "警告", {
226-
confirmButtonText: "确定",
227-
cancelButtonText: "取消",
228-
type: "warning"
229-
});
230-
const userName = this.userData.userName;
231-
const passWord = this.userData.passWord;
232-
const checkPassWord = this.userData.passWord2;
233-
if (type === 1) {
234-
if (userName.length > 18 || userName < 2)
235-
return this.$message({
236-
message: "用户名规则不正确,请检查后重试",
237-
type: "error"
242+
async update() {
243+
await this.$refs.ruleFormRef.validate(async (valid) => {
244+
if (!valid) return;
245+
await this.$confirm("确定要更改此信息吗?", "警告", {
246+
confirmButtonText: "确定",
247+
cancelButtonText: "取消",
248+
type: "warning"
249+
});
250+
const passWord = this.userData.passWord;
251+
try {
252+
await request({
253+
method: "PUT",
254+
url: API_USER_UPDATE,
255+
data: {
256+
passWord
257+
}
238258
});
239-
}
240-
if (type === 2) {
241-
if (passWord.length > 18 || passWord.length < 6 || checkPassWord !== passWord)
242-
return this.$message({
243-
message: "密码规则不正确或两次密码不一致,请检查后重试",
259+
this.$message({ message: "用户数据已更新", type: "success" });
260+
} catch (error) {
261+
this.$message({
262+
message: "用户资料更新失败,可能是用户名冲突或服务器暂时不可用",
244263
type: "error"
245264
});
246-
}
247-
try {
248-
await request({
249-
method: "PUT",
250-
url: API_USER_UPDATE,
251-
data: {
252-
userName,
253-
passWord
254-
}
255-
});
256-
this.$message({ message: "用户数据已更新", type: "success" });
257-
} catch (error) {
258-
this.$message({
259-
message: "用户资料更新失败,可能是用户名冲突或服务器暂时不可用",
260-
type: "error"
261-
});
262-
}
265+
}
266+
});
263267
},
264268
265269
async changeApi(enable) {
@@ -279,6 +283,19 @@ export default {
279283
type: "error"
280284
});
281285
}
286+
},
287+
validatePassword(rule, value = "", callback) {
288+
if (!value) return callback(new Error("请输入密码值,若不输入则不进行密码修改"));
289+
if (value.length < 12 || value.length > 36)
290+
return callback(new Error("密码长度不规范,必须长度在 12 位到 36 位之间"));
291+
const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[0-9A-Za-z]{12,}$/;
292+
if (!reg.test(value)) return callback(new Error("您的密码必须包含:数字,大写和小写字母"));
293+
callback();
294+
},
295+
validatePassword2(rule, value = "", callback) {
296+
if (value !== this.passWord) return callback(new Error("两次密码不一致"));
297+
298+
callback();
282299
}
283300
},
284301
components: { Panel, LineLabel }

src/app/views/Users.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<template #default>
156156
<div>
157157
<div class="sub-title">
158-
<p class="sub-title-title">用户昵称</p>
158+
<p class="sub-title-title require-field">用户昵称</p>
159159
<p class="sub-title-info">必填,6到12个字符,支持中文,英文和字符</p>
160160
</div>
161161
<el-input
@@ -164,12 +164,12 @@
164164
size="small"
165165
></el-input>
166166
<div class="sub-title row-mt">
167-
<p class="sub-title-title">重置密码</p>
167+
<p class="sub-title-title require-field">重置密码</p>
168168
<p class="sub-title-info">不填写则不更变原有值</p>
169169
</div>
170170
<el-input v-model="editUserInfo.passWord" placeholder="原值" size="small"></el-input>
171171
<div class="sub-title row-mt">
172-
<p class="sub-title-title">权限</p>
172+
<p class="sub-title-title require-field">权限</p>
173173
<p class="sub-title-info">普通权限适用于商业用户,最高权限适用于管理人员</p>
174174
</div>
175175
<el-select v-model="editUserInfo.permission" placeholder="请选择" size="small">
@@ -365,7 +365,7 @@ export default {
365365
for (const v of this.multipleSelection) {
366366
uuids.push(v.uuid);
367367
}
368-
if(!uuids.length){
368+
if (!uuids.length) {
369369
throw new Error("请至少选择一个用户");
370370
}
371371
await request({

0 commit comments

Comments
 (0)