show current profile in user profile page

This commit is contained in:
MaysWind
2020-10-29 01:32:54 +08:00
parent 5c0d169a26
commit be19089eab
4 changed files with 45 additions and 1 deletions
+3
View File
@@ -72,6 +72,9 @@ export default {
refreshToken: () => {
return axios.post('v1/tokens/refresh.json');
},
getProfile: () => {
return axios.get('v1/users/profile/get.json');
},
updateProfile: ({ email, nickname, password }) => {
return axios.post('v1/users/profile/update.json', {
email,
+1
View File
@@ -103,6 +103,7 @@ export default {
'You have been successfully registered': 'You have been successfully registered',
'Unable to sign up': 'Unable to sign up',
'User registration is disabled': 'User registration is disabled',
'Unable to get user profile': 'Unable to get user profile',
'Nothing has been modified': 'Nothing has been modified',
'Your profile has been successfully updated': 'Your profile has been successfully updated',
'Unable to update user profile': 'Unable to update user profile',
+1
View File
@@ -103,6 +103,7 @@ export default {
'You have been successfully registered': '注册成功',
'Unable to sign up': '无法注册',
'User registration is disabled': '用户注册已禁用',
'Unable to get user profile': '无法获取用户信息',
'Nothing has been modified': '没有修改的项目',
'Your profile has been successfully updated': '您的用户信息更新成功',
'Unable to update user profile': '无法更新用户信息',
+40 -1
View File
@@ -67,6 +67,8 @@ export default {
inputIsNotChangedProblemMessage() {
if (!this.password && !this.confirmPassword && !this.email && !this.nickname) {
return 'Nothing has been modified';
} else if (!this.password && !this.confirmPassword && this.email === this.oldEmail && this.nickname === this.oldNickname) {
return 'Nothing has been modified';
} else if (!this.password && this.confirmPassword) {
return 'Password cannot be empty';
} else if (this.password && !this.confirmPassword) {
@@ -83,6 +85,43 @@ export default {
}
}
},
created() {
const self = this;
const app = self.$f7;
const router = self.$f7router;
app.preloader.show();
self.$services.getProfile().then(response => {
app.preloader.hide();
const data = response.data;
if (!data || !data.success || !data.result) {
self.$alert('Unable to get user profile', () => {
router.back();
});
return;
}
self.oldEmail = data.result.email;
self.oldNickname = data.result.nickname;
self.email = self.oldEmail
self.nickname = self.oldNickname;
}).catch(error => {
app.preloader.hide();
if (error.response && error.response.data && error.response.data.errorMessage) {
self.$alert({ error: error.response.data }, () => {
router.back();
});
} else {
self.$alert('Unable to get user profile', () => {
router.back();
});
}
});
},
methods: {
update() {
const self = this;
@@ -127,7 +166,7 @@ export default {
}
self.$toast('Your profile has been successfully updated');
router.back();
router.back('/settings', { force: true });
}).catch(error => {
hasResponse = true;
app.preloader.hide();