Skip to content

Commit f755534

Browse files
authored
Merge branch 'master' into improve-problem-list-add-problem
2 parents 605f1a7 + 69017c9 commit f755534

File tree

4 files changed

+145
-2
lines changed

4 files changed

+145
-2
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: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
if(err.request.status === 403) {
64+
callback(new Error('Old Password Wrong'));
65+
} else {
66+
callback(new Error('Unkown Error'));
67+
}
68+
});
69+
};
70+
return {
71+
ldata: {
72+
oldpassword: '',
73+
newpassword: '',
74+
newpasswdrepeat: ''
75+
},
76+
rules: {
77+
newpassword: [
78+
{ required: true, message: 'Input your password', trigger: 'blur' },
79+
{ min: 6, message: 'No less than 6 characters', trigger: 'blur' }
80+
],
81+
newpasswdrepeat: [
82+
{ required: true, message: 'Repeat your password', trigger: 'blur' },
83+
{ validator: validatePasswd, trigger: 'blur' }
84+
],
85+
oldpassword: [
86+
{ validator: validateOldPasswd, trigger: 'blur' }
87+
]
88+
},
89+
old_password_required: false,
90+
buttonLoading: false
91+
};
92+
},
93+
methods: {
94+
submit() {
95+
this.buttonLoading = true;
96+
this.$axios
97+
.patch(apiurl('/account/password'), {
98+
password: this.ldata.newpassword
99+
})
100+
.then(() => {
101+
this.buttonLoading = false;
102+
this.$SegmentMessage.success(this, 'Changed successfully');
103+
})
104+
.catch(err => {
105+
if (err.request.status === 401) {
106+
this.$SegmentMessage.error(this, 'Please login first');
107+
this.$store.state.user.showlogin = true;
108+
}
109+
if (err.request.status === 403) {
110+
this.$SegmentMessage.error(this, 'Please enter your old password');
111+
this.old_password_required = true;
112+
}
113+
this.buttonLoading = false;
114+
});
115+
},
116+
onSubmit() {
117+
this.$refs['ChangePasswordForm'].validate((valid) => {
118+
if (valid) {
119+
this.submit();
120+
} else {
121+
return false;
122+
}
123+
});
124+
},
125+
reset() {
126+
this.$refs['ChangePasswordForm'].resetFields();
127+
this.old_password_required = false;
128+
}
129+
}
130+
};
131+
</script>
132+
133+
<style scoped>
134+
.icon-lable {
135+
margin-bottom: 5px;
136+
}
137+
</style>

src/components/user/register.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ export default {
8585
}
8686
};
8787
let validateUsername = (rule, value, callback) => {
88+
if(value === '') {
89+
callback();
90+
}
8891
this.$axios
8992
.get(apiurl('account/username/accessibility/' + value))
9093
.then(() => {
@@ -94,7 +97,7 @@ export default {
9497
if (err.request.status === 409) {
9598
callback(new Error('The user name is already in use'));
9699
} else {
97-
callback();
100+
callback(new Error('Unkown Error'));
98101
}
99102
});
100103
};

src/router.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ let router = new Router({
77
routes: [{
88
path: '/',
99
component: () => import('./components/home/page.vue')
10+
}, {
11+
path: '/account/password',
12+
component: () => import('./components/user/changePassword.vue')
1013
}, {
1114
path: '/account/:id',
1215
component: () => import('./components/user/content.vue')

0 commit comments

Comments
 (0)