password-reset.js
3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { mapGetters, mapActions, mapState } from "vuex";
import api from '@/api/api'
import {
httpGet,
httpPost
} from '@/api/fetch-api.js'
import modalComp from '@/components/modal-comp/modal-comp.vue';
import { passwordEncrypt } from '@/utils/encrypt.js';
export default {
data() {
return {
key: 'value',
type: 1, // 1:输入用户信息 2:找回密码 3:核对信息 4.重置密码
values: {
cid: "",
oldPwd: "",
pwd: "",
pwdRepeat: ""
},
step: {
error0: "",
error1: "",
error2: "",
},
times: {
interval: 0, // 索引
remain: 0, // 剩余时间
tip: "" // 显示的文字
},
modalVisiable: false,
targetPath: "",
modalIcon: "succ",
modalContent: ""
}
},
methods: {
initData() { },
i18n() {
let i18n = this.$i18n.messages[this.$i18n.locale] || {};
return i18n;
},
showModal(content, icon) {
icon = !icon || typeof icon === "undefined" ? "succ" : "succ";
this.modalIcon = icon;
this.modalContent = content;
this.modalVisiable = true;
},
resetPwd() {
if (!this.values.oldPwd) {
this.step.error0 = this.i18n().passwordReset.oldPwdPlaceholde;
return;
}
let c1 = this.checkPassword(this.values.pwd);
if (c1) {
this.$set(this.step, 'error1', c1);
return;
}
if (this.values.pwdRepeat != this.values.pwd) {
this.step.error2 = this.i18n().passwordCheck.error3;
return;
}
let newPwd = passwordEncrypt(this.values.pwd);
let oldPwd = passwordEncrypt(this.values.oldPwd);
httpPost({
url: api.changePassword,
data: {
oldPwd: oldPwd,
newPwd: newPwd
},
sid: true
}).then(response => {
this.targetPath = "";
let message = this.i18n().passwordCheck.success;
switch (response.returnCode) {
case "0":
this.targetPath = "";
this.showModal(message, "succ");
break
case "COMMON_ERROR_E0":
message = this.i18n().session.sidExpire;
this.targetPath = "/login?callback=/password/reset";
this.showModal(message, "info");
break;
default:
this.step.error0 = this.i18n().passwordCheck.error5;
break;
}
}).catch(err => {
let message = this.i18n().session.sidExpire;
this.targetPath = "/login?callback=/password/reset";
this.showModal(message, "info");
});
},
checkPassword(password) {
if (password.length < 8) {
return this.i18n().passwordCheck.error1;
}
// 匹配字母
let m1 = /([a-z])+/.test(password);
let m2 = /([A-Z])+/.test(password);
// 匹配数字
let m3 = /([0-9])+/.test(password);
// 匹配特殊字符
let m4 = /[^a-zA-Z0-9]+/.test(password);
if ((m1 | m2) & m3 & m4) {
return "";
} else {
return this.i18n().passwordCheck.error2
}
},
modalCallback() {
this.modalVisiable = false;
if (this.targetPath) {
this.$router.push({
"path": this.targetPath
});
}
}
},
watch: {
'values.oldPwd': function () {
this.$set(this.step, 'error0', '');
},
'values.pwd': function () {
this.$set(this.step, 'error1', this.checkPassword(this.values.pwd));
},
'values.pwdRepeat': function () {
if (this.values.pwdRepeat != this.values.pwd) {
this.$set(this.step, 'error2', this.i18n().passwordCheck.error3);
} else {
this.$set(this.step, 'error2', '');
}
},
},
mounted() { },
created() { },
components: {
modalComp
}
}