修改密码
This commit is contained in:
parent
68efed66fe
commit
8880599f29
|
@ -27,4 +27,6 @@ public interface UserMapper {
|
|||
int updateByPrimaryKeySelective(User record);
|
||||
|
||||
int updateByPrimaryKey(User record);
|
||||
|
||||
int updatePassword(User record);
|
||||
}
|
|
@ -303,4 +303,12 @@
|
|||
phone = #{phone,jdbcType=VARCHAR}
|
||||
where id = #{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
<!--修改密码-->
|
||||
<update id="updatePassword" parameterType="io.metersphere.base.domain.User">
|
||||
update user
|
||||
set
|
||||
password=#{password,jdbcType=VARCHAR},
|
||||
update_time = #{updateTime,jdbcType=BIGINT}
|
||||
where id=#{id,jdbcType=VARCHAR}
|
||||
</update>
|
||||
</mapper>
|
|
@ -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<User> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package io.metersphere.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserPassDTO {
|
||||
private String password;
|
||||
private String newpassword;
|
||||
private String id;
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
<el-card>
|
||||
<template v-slot:header>
|
||||
<div>
|
||||
<el-row type="flex" justify="space-between" align="middle">
|
||||
<el-row type="flex" just ify="space-between" align="middle">
|
||||
<span class="title">{{$t('commons.personal_info')}}</span>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!--Personal information menu-->
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
<el-table-column prop="id" label="ID"/>
|
||||
<el-table-column prop="name" :label="$t('commons.username')" width="120"/>
|
||||
|
@ -30,7 +31,9 @@
|
|||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
|
||||
<!--Modify personal details-->
|
||||
<el-dialog :title="$t('member.modify_personal_info')" :visible.sync="updateVisible" width="30%"
|
||||
:destroy-on-close="true" @close="handleClose">
|
||||
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule"
|
||||
|
@ -55,12 +58,9 @@
|
|||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<el-dialog
|
||||
:title="$t('member.edit_password')"
|
||||
:visible.sync="centerDialogVisible"
|
||||
width="30%"
|
||||
left>
|
||||
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
|
||||
<!--Change personal password-->
|
||||
<el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%" left>
|
||||
<el-form :model="ruleForm" :rules="rules" ref="editPasswordForm" label-width="100px" class="demo-ruleForm">
|
||||
<el-form-item :label="$t('member.old_password')" prop="password">
|
||||
<el-input v-model="ruleForm.password" autocomplete="off" show-password/>
|
||||
</el-form-item>
|
||||
|
@ -69,12 +69,13 @@
|
|||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="centerDialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
|
||||
<ms-dialog-footer
|
||||
@cancel="editPasswordVisible = false"
|
||||
@confirm="updatePassword('editPasswordForm')"/>
|
||||
</span>
|
||||
</el-dialog>
|
||||
|
||||
</el-card>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -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 = {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<ms-table-header :condition.sync="condition" @search="search" @create="create"
|
||||
:create-tip="btnTips" :title="$t('commons.member')"/>
|
||||
</template>
|
||||
|
||||
<el-table :data="tableData" style="width: 100%">
|
||||
<el-table-column type="selection" width="55"/>
|
||||
<el-table-column prop="id" label="ID"/>
|
||||
|
@ -31,15 +32,18 @@
|
|||
<el-table-column :label="$t('commons.operating')">
|
||||
<template v-slot:default="scope">
|
||||
<ms-table-operator @editClick="edit(scope.row)" @deleteClick="del(scope.row)"/>
|
||||
<el-tooltip class="editpassword" effect="dark" :content="$t('member.edit_password')" placement="bottom" >
|
||||
<el-button @click="editPassword(scope.row)" type="primary" icon="el-icon-s-tools" size="mini" circle/>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<ms-table-pagination :change="search" :current-page.sync="currentPage" :page-size.sync="pageSize"
|
||||
:total="total"/>
|
||||
|
||||
</el-card>
|
||||
|
||||
<!--Create user-->
|
||||
<el-dialog :title="$t('user.create')" :visible.sync="createVisible" width="30%" @closed="handleClose"
|
||||
:destroy-on-close="true">
|
||||
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule" ref="createUserForm">
|
||||
|
@ -66,6 +70,7 @@
|
|||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!--Modify user information in system settings-->
|
||||
<el-dialog :title="$t('user.modify')" :visible.sync="updateVisible" width="30%" :destroy-on-close="true"
|
||||
@close="handleClose">
|
||||
<el-form :model="form" label-position="right" label-width="100px" size="small" :rules="rule" ref="updateUserForm">
|
||||
|
@ -81,10 +86,6 @@
|
|||
<el-form-item :label="$t('commons.phone')" prop="phone">
|
||||
<el-input v-model="form.phone" autocomplete="off"/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('commons.password')" prop="password">
|
||||
<el-input v-model="form.password" autocomplete="off" show-password/>
|
||||
</el-form-item>
|
||||
<!--<el-input placeholder="请输入密码" v-model="input" show-password></el-input>-->
|
||||
</el-form>
|
||||
<template v-slot:footer>
|
||||
<ms-dialog-footer
|
||||
|
@ -92,21 +93,24 @@
|
|||
@confirm="updateUser('updateUserForm')"/>
|
||||
</template>
|
||||
</el-dialog>
|
||||
<!--<el-dialog
|
||||
:title="$t('member.edit_password')"
|
||||
:visible.sync="centerDialogVisible"
|
||||
width="30%"
|
||||
left>
|
||||
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
|
||||
<el-form-item label="新密码" prop="newPass">
|
||||
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
|
||||
Changing user password in system settings
|
||||
|
||||
<!--Changing user password in system settings-->
|
||||
<el-dialog :title="$t('member.edit_password')" :visible.sync="editPasswordVisible" width="30%" left>
|
||||
<el-form :model="ruleForm" label-position="right" label-width="100px" size="small" :rules="rule" ref="editPasswordForm" class="demo-ruleForm">
|
||||
<el-form-item :label="$t('member.new_password')" prop="newpassword">
|
||||
<el-input type="password" v-model="ruleForm.newpassword" autocomplete="off" show-password></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item >
|
||||
<el-input v-model="ruleForm.id" autocomplete="off" :disabled="true" style="display:none"/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="centerDialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="centerDialogVisible = false">确 定</el-button>
|
||||
<ms-dialog-footer
|
||||
@cancel="editPasswordVisible = false"
|
||||
@confirm="editUserPassword('editPasswordForm')"/>
|
||||
</span>
|
||||
</el-dialog>-->
|
||||
</el-dialog>
|
||||
|
||||
</div>
|
||||
</template>
|
||||
|
@ -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 @@
|
|||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
.editpassword{
|
||||
margin-left: 10px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -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',
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue