diff --git a/pkg/api/users.go b/pkg/api/users.go index 2c06495b..0c5ed65b 100644 --- a/pkg/api/users.go +++ b/pkg/api/users.go @@ -131,8 +131,16 @@ func (a *UsersApi) UserUpdateProfileHandler(c *core.Context) (interface{}, *errs userUpdateReq.Email = "" } - if userUpdateReq.Password != "" && !a.users.IsPasswordEqualsUserPassword(userUpdateReq.Password, user) { - anythingUpdate = true + if userUpdateReq.Password != "" { + if !a.users.IsPasswordEqualsUserPassword(userUpdateReq.OldPassword, user) { + return nil, errs.ErrUserPasswordWrong + } + + if !a.users.IsPasswordEqualsUserPassword(userUpdateReq.Password, user) { + anythingUpdate = true + } else { + userUpdateReq.Password = "" + } } else { userUpdateReq.Password = "" } diff --git a/pkg/models/user.go b/pkg/models/user.go index 6088ed3c..44954787 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -39,9 +39,10 @@ type UserRegisterRequest struct { } type UserProfileUpdateRequest struct { - Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"` - Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"` - Password string `json:"password" binding:"omitempty,min=6,max=128"` + Email string `json:"email" binding:"omitempty,notBlank,max=100,validEmail"` + Nickname string `json:"nickname" binding:"omitempty,notBlank,max=64"` + Password string `json:"password" binding:"omitempty,min=6,max=128"` + OldPassword string `json:"oldPassword" binding:"omitempty,min=6,max=128"` } type UserProfileResponse struct { diff --git a/src/lib/services.js b/src/lib/services.js index e840856b..395c0082 100644 --- a/src/lib/services.js +++ b/src/lib/services.js @@ -127,11 +127,12 @@ export default { getProfile: () => { return axios.get('v1/users/profile/get.json'); }, - updateProfile: ({ email, nickname, password }) => { + updateProfile: ({ email, nickname, password, oldPassword }) => { return axios.post('v1/users/profile/update.json', { email, nickname, - password + password, + oldPassword }); }, }; diff --git a/src/locales/en.js b/src/locales/en.js index f13c471a..3d2ac1d3 100644 --- a/src/locales/en.js +++ b/src/locales/en.js @@ -48,6 +48,7 @@ export default { 'password': 'Password', 'email': 'Email', 'nickname': 'Nickname', + 'oldPassword': 'Current Password', }, 'parameterizedError': { 'parameter invalid': '{parameter} is invalid', @@ -64,6 +65,7 @@ export default { 'Close': 'Close', 'Update': 'Update', 'Done': 'Done', + 'Continue': 'Continue', 'Version': 'Version', 'User': 'User', 'Application': 'Application', @@ -113,6 +115,8 @@ export default { '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', + 'Current Password': 'Current Password', + 'Please enter your current password when modifying your password': 'Please enter your current password when modifying your password', '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', diff --git a/src/locales/zh_Hans.js b/src/locales/zh_Hans.js index 056b2735..0a14af34 100644 --- a/src/locales/zh_Hans.js +++ b/src/locales/zh_Hans.js @@ -48,6 +48,7 @@ export default { 'password': '密码', 'email': '电子邮箱', 'nickname': '昵称', + 'oldPassword': '当前密码', }, 'parameterizedError': { 'parameter invalid': '{parameter}无效', @@ -64,6 +65,7 @@ export default { 'Close': '关闭', 'Update': '更新', 'Done': '完成', + 'Continue': '继续', 'Version': '版本', 'User': '用户', 'Application': '应用', @@ -113,6 +115,8 @@ export default { 'Unable to sign up': '无法注册', 'User registration is disabled': '用户注册已禁用', 'Unable to get user profile': '无法获取用户信息', + 'Current Password': '当前密码', + 'Please enter your current password when modifying your password': '修改密码时请输入您的当前密码', 'Nothing has been modified': '没有修改的项目', 'Your profile has been successfully updated': '您的用户信息更新成功', 'Unable to update user profile': '无法更新用户信息', diff --git a/src/views/mobile/users/UserProfile.vue b/src/views/mobile/users/UserProfile.vue index d642f7f0..142e0465 100644 --- a/src/views/mobile/users/UserProfile.vue +++ b/src/views/mobile/users/UserProfile.vue @@ -42,6 +42,32 @@ + + +
+
+
+
+
+

{{ $t('Please enter your current password when modifying your password') }}

+ + + + +
+
+
@@ -49,12 +75,14 @@ export default { data() { return { + currentPassword: '', password: '', confirmPassword: '', oldEmail: '', email: '', oldNickname: '', - nickname: '' + nickname: '', + showInputPasswordSheet: false }; }, computed: { @@ -128,6 +156,8 @@ export default { const app = self.$f7; const router = self.$f7router; + self.showInputPasswordSheet = false; + let problemMessage = self.inputIsNotChangedProblemMessage || self.inputInvalidProblemMessage; if (problemMessage) { @@ -135,6 +165,11 @@ export default { return; } + if (self.password && !self.currentPassword) { + self.showInputPasswordSheet = true; + return; + } + let hasResponse = false; setTimeout(() => { @@ -145,11 +180,14 @@ export default { self.$services.updateProfile({ password: self.password, + oldPassword: self.currentPassword, email: self.email, nickname: self.nickname }).then(response => { hasResponse = true; app.preloader.hide(); + self.currentPassword = ''; + const data = response.data; if (!data || !data.success || !data.result) { @@ -170,6 +208,7 @@ export default { }).catch(error => { hasResponse = true; app.preloader.hide(); + self.currentPassword = ''; if (error.response && error.response.data && error.response.data.errorMessage) { self.$alert({ error: error.response.data }); @@ -181,3 +220,14 @@ export default { } }; + +