diff --git a/backend/src/main/java/io/metersphere/base/mapper/UserMapper.java b/backend/src/main/java/io/metersphere/base/mapper/UserMapper.java index 286dd2ab87..c568b3d43a 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/UserMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/UserMapper.java @@ -27,4 +27,6 @@ public interface UserMapper { int updateByPrimaryKeySelective(User record); int updateByPrimaryKey(User record); + + int updatePassword(User record); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/UserMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/UserMapper.xml index f8b0050e35..bb2eee9114 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/UserMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/UserMapper.xml @@ -303,4 +303,12 @@ phone = #{phone,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} + + + update user + set + password=#{password,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=BIGINT} + where id=#{id,jdbcType=VARCHAR} + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 4d2a968141..e026a95ec3 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -13,6 +13,7 @@ import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserPassDTO; import io.metersphere.service.OrganizationService; import io.metersphere.service.UserService; import io.metersphere.service.WorkspaceService; @@ -241,5 +242,17 @@ public class UserController { public List getBesideOrgMemberList(@PathVariable String orgId) { return userService.getBesideOrgMemberList(orgId); } + /* + * 修改当前用户密码 + * */ + @PostMapping("/update/password") + public int updateCurrentUserPassword(@RequestBody UserPassDTO UserPassDTO) { + return userService.updatePassword(UserPassDTO); + } + /*管理员修改用户密码*/ + @PostMapping("/special/password") + public int updateUserPassword(@RequestBody UserPassDTO UserPassDTO) { + return userService.updateUserPassword(UserPassDTO); + } } diff --git a/backend/src/main/java/io/metersphere/dto/UserPassDTO.java b/backend/src/main/java/io/metersphere/dto/UserPassDTO.java new file mode 100644 index 0000000000..645ecee176 --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/UserPassDTO.java @@ -0,0 +1,10 @@ +package io.metersphere.dto; + +import lombok.Data; + +@Data +public class UserPassDTO { + private String password; + private String newpassword; + private String id; +} diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index b40f1c4869..fc5d745a1c 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -12,6 +12,7 @@ import io.metersphere.controller.request.member.QueryMemberRequest; import io.metersphere.controller.request.organization.AddOrgMemberRequest; import io.metersphere.controller.request.organization.QueryOrgMemberRequest; import io.metersphere.dto.UserDTO; +import io.metersphere.dto.UserPassDTO; import io.metersphere.i18n.Translator; import io.metersphere.user.SessionUser; import io.metersphere.user.SessionUtils; @@ -256,4 +257,42 @@ public class UserService { SessionUtils.getUser().setLanguage(lang); } } + + /*修改当前用户用户密码*/ + private User getUserPassDTO(UserPassDTO UserPassDTO) { + if (SessionUtils.getUser() != null) { + User user = userMapper.selectByPrimaryKey(SessionUtils.getUser().getId()); + String pwd = user.getPassword(); + String prepwd = CodingUtil.md5(UserPassDTO.getPassword(),"utf-8"); + String newped = UserPassDTO.getNewpassword(); + if (StringUtils.isNotBlank(prepwd)) { + if (prepwd.trim().equals(pwd.trim())) { + user.setPassword(CodingUtil.md5(newped)); + user.setUpdateTime(System.currentTimeMillis()); + return user; + } + } + MSException.throwException("密码修改失败"); + } + return null; + } + + public int updatePassword(UserPassDTO UserPassDTO) { + User user = getUserPassDTO(UserPassDTO); + return userMapper.updatePassword(user); + } + /*管理员修改用户密码*/ + private User getUserDTO(UserPassDTO UserPassDTO){ + User user= userMapper.selectByPrimaryKey(UserPassDTO.getId()); + String newped = UserPassDTO.getNewpassword(); + user.setPassword(CodingUtil.md5(newped)); + user.setUpdateTime(System.currentTimeMillis()); + return user; + } + public int updateUserPassword(UserPassDTO UserPassDTO){ + User user=getUserDTO(UserPassDTO); + int i=userMapper.updatePassword(user); + return i; + } + } diff --git a/frontend/src/business/components/settings/personal/PersonSetting.vue b/frontend/src/business/components/settings/personal/PersonSetting.vue index 1636858429..e4627660d8 100644 --- a/frontend/src/business/components/settings/personal/PersonSetting.vue +++ b/frontend/src/business/components/settings/personal/PersonSetting.vue @@ -3,12 +3,13 @@ + @@ -30,7 +31,9 @@ + + - - + + + @@ -69,12 +69,13 @@ - 取 消 - 确 定 + - + @@ -84,21 +85,13 @@ export default { data() { - var validatePass2 = (rule, value, callback) => { - if (value === '') { - callback(new Error('请再次输入密码')); - } else if (value == this.ruleForm.newpassword) { - callback(new Error('两次密码一致,请重新输入!')); - } else { - callback(); - } - }; return { result: {}, updateVisible: false, - centerDialogVisible:false, + editPasswordVisible:false, tableData: [], updatePath: '/user/update/current', + updatePasswordPath:'/user/update/password', form: {}, ruleForm:{}, rule: { @@ -131,7 +124,7 @@ ], }, rules:{ - password: [ + /*password: [ {required: true, message: this.$t('user.input_password'), trigger: 'blur'}, { required:true, @@ -139,7 +132,7 @@ message: this.$t('member.password_format_is_incorrect'), trigger: 'blur' } - ], + ],*/ newpassword: [ {required: true, message: this.$t('user.input_password'), trigger: 'blur'}, { @@ -148,7 +141,6 @@ message: this.$t('member.password_format_is_incorrect'), trigger: 'blur' }, - { validator: validatePass2, trigger: 'blur' } ] } } @@ -168,7 +160,7 @@ this.form = Object.assign({}, row); }, editPassword(row){ - this.centerDialogVisible = true; + this.editPasswordVisible = true; }, updateUser(updateUserForm) { this.$refs[updateUserForm].validate(valide => { @@ -185,6 +177,20 @@ } }) }, + updatePassword(editPasswordForm){ + this.$refs[editPasswordForm].validate(valide=>{ + if(valide){ + this.result = this.$post(this.updatePasswordPath, this.ruleForm, response => { + this.$success(this.$t('commons.modify_success')); + this.editPasswordVisible = false; + this.initTableData(); + window.location.reload(); + }); + }else { + return false; + } + }) + }, initTableData() { this.result = this.$get("/user/info/" + this.currentUser().id, response => { let data = response.data; @@ -195,6 +201,7 @@ }, handleClose() { this.form = {}; + this.ruleForm = {}; } } } diff --git a/frontend/src/business/components/settings/system/User.vue b/frontend/src/business/components/settings/system/User.vue index 45147e5b66..ba63561fea 100644 --- a/frontend/src/business/components/settings/system/User.vue +++ b/frontend/src/business/components/settings/system/User.vue @@ -1,11 +1,12 @@ + @@ -81,10 +86,6 @@ - - - - - + + + + + + + - 取 消 - 确 定 + - --> + @@ -123,14 +127,15 @@ components: {MsCreateBox, MsTablePagination, MsTableHeader, MsTableOperator, MsDialogFooter}, data() { return { - /*input:'',*/ queryPath: '/user/special/list', deletePath: '/user/special/delete/', createPath: '/user/special/add', updatePath: '/user/special/update', + editPasswordPath:'/user/special/password', result: {}, createVisible: false, updateVisible: false, + editPasswordVisible:false, multipleSelection: [], currentPage: 1, pageSize: 5, @@ -139,6 +144,7 @@ condition: {}, tableData: [], form: {}, + ruleForm: {}, rule: { id: [ {required: true, message: this.$t('user.input_id'), trigger: 'blur'}, @@ -179,6 +185,15 @@ message: this.$t('member.password_format_is_incorrect'), trigger: 'blur' } + ], + newpassword: [ + {required: true, message: this.$t('user.input_password'), trigger: 'blur'}, + { + required:true, + pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[^]{8,16}$/, + message: this.$t('member.password_format_is_incorrect'), + trigger: 'blur' + } ] } } @@ -194,6 +209,10 @@ this.updateVisible = true; this.form = Object.assign({}, row); }, + editPassword(row){ + this.editPasswordVisible=true; + this.ruleForm = Object.assign({}, row); + }, del(row) { this.$confirm(this.$t('user.delete_confirm'), '', { confirmButtonText: this.$t('commons.confirm'), @@ -234,6 +253,20 @@ } }) }, + editUserPassword(editPasswordForm){ + this.$refs[editPasswordForm].validate(valide=>{ + if(valide){ + this.result = this.$post(this.editPasswordPath, this.ruleForm, response => { + this.$success(this.$t('commons.modify_success')); + this.editPasswordVisible = false; + this.search() ; + window.location.reload(); + }); + }else { + return false; + } + }) + }, search() { this.result = this.$post(this.buildPagePath(this.queryPath), this.condition, response => { let data = response.data; @@ -260,5 +293,7 @@ diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index 2e8fceefb6..9ea2a7f6e9 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -97,7 +97,6 @@ export default { 'mobile_number_format_is_incorrect': 'Mobile number format is incorrect', 'email_format_is_incorrect': 'Email format is incorrect', 'password_format_is_incorrect': 'Password format is incorrect (At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter and 1 number)', - 'password_format_is_incorrect':'Password format is incorrect (At least 8-16 characters, at least 1 uppercase letter, 1 lowercase letter and 1 number)', 'old_password':'Old Password', 'new_password':'New Password', },