Skip to content

Commit 72cfafc

Browse files
committed
add change password
1 parent 57e79fe commit 72cfafc

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

src/components/lib/problemTag.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<span class="tag" :style="style">
3-
<i :v-if="icon" :class="'el-icon-' + icon_detail"></i>{{content}}
3+
<i v-if="icon" :class="'el-icon-' + icon_detail"></i>{{content}}
44
</span>
55
</template>
66

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<template>
2+
<div>
3+
<el-form :model="ldata" ref="ChangePasswordForm" :rules="rules">
4+
<div class="icon-lable">
5+
<i class="el-icon-lock" />
6+
New Password
7+
</div>
8+
<el-form-item prop="newpassword">
9+
<el-input type="password" v-model="ldata.newpassword"></el-input>
10+
</el-form-item>
11+
<div class="icon-lable">
12+
<i class="el-icon-lock" />
13+
Repeat New Password
14+
</div>
15+
<el-form-item prop="newpasswdrepeat">
16+
<el-input type="password" v-model="ldata.newpasswdrepeat"></el-input>
17+
</el-form-item>
18+
<div v-if="old_password_required">
19+
<div class="icon-lable">
20+
<i class="el-icon-lock" />
21+
Old Password
22+
</div>
23+
<el-form-item prop="oldpassword">
24+
<el-input type="password" v-model="ldata.oldpassword"></el-input>
25+
</el-form-item>
26+
</div>
27+
<el-form-item>
28+
<el-button
29+
type="primary"
30+
v-on:click="onSubmit();"
31+
:loading="buttonLoading"
32+
>
33+
Change
34+
</el-button>
35+
<el-button v-on:click="reset();">Reset</el-button>
36+
</el-form-item>
37+
</el-form>
38+
</div>
39+
</template>
40+
41+
<script>
42+
import apiurl from './../../apiurl';
43+
44+
export default {
45+
name: 'UserChangePassword',
46+
data() {
47+
let validatePasswd = (rule, value, callback) => {
48+
if (value === '' || value === this.ldata.newpassword) {
49+
callback();
50+
} else {
51+
callback(new Error('Password mismatch'));
52+
}
53+
};
54+
let validateOldPasswd = (rule, value, callback) => {
55+
this.$axios
56+
.post(apiurl('/account/password'), {
57+
password: this.ldata.oldpassword
58+
})
59+
.then(() => {
60+
callback();
61+
})
62+
.catch(err => {
63+
console.log(err.request.status);
64+
callback(new Error('Old Password Wrong'));
65+
});
66+
};
67+
return {
68+
ldata: {
69+
oldpassword: '',
70+
newpassword: '',
71+
newpasswdrepeat: ''
72+
},
73+
rules: {
74+
newpassword: [
75+
{ required: true, message: 'Input your password', trigger: 'blur' },
76+
{ min: 6, message: 'No less than 6 characters', trigger: 'blur' }
77+
],
78+
newpasswdrepeat: [
79+
{ required: true, message: 'Repeat your password', trigger: 'blur' },
80+
{ validator: validatePasswd, trigger: 'blur' }
81+
],
82+
oldpassword: [
83+
{ validator: validateOldPasswd, trigger: 'blur' }
84+
]
85+
},
86+
old_password_required: false,
87+
buttonLoading: false
88+
};
89+
},
90+
methods: {
91+
submit() {
92+
this.buttonLoading = true;
93+
this.$axios
94+
.patch(apiurl('/account/password'), {
95+
password: this.ldata.newpassword
96+
})
97+
.then(() => {
98+
this.buttonLoading = false;
99+
this.$SegmentMessage.success(this, 'Changed successfully');
100+
})
101+
.catch(err => {
102+
console.table(err);
103+
if (err.request.status === 401) {
104+
this.$SegmentMessage.error(this, 'Please login first');
105+
this.$store.state.user.showlogin = true;
106+
}
107+
if (err.request.status === 403) {
108+
this.$SegmentMessage.error(this, 'Please enter your old password');
109+
this.old_password_required = true;
110+
}
111+
this.buttonLoading = false;
112+
});
113+
},
114+
onSubmit() {
115+
this.$refs['ChangePasswordForm'].validate((valid) => {
116+
if (valid) {
117+
this.submit();
118+
} else {
119+
return false;
120+
}
121+
});
122+
},
123+
reset() {
124+
this.$refs['ChangePasswordForm'].resetFields();
125+
this.old_password_required = false;
126+
}
127+
}
128+
};
129+
</script>
130+
131+
<style scoped>
132+
.icon-lable {
133+
margin-bottom: 5px;
134+
}
135+
</style>

0 commit comments

Comments
 (0)