#I5MD0X 增加修改自己登录密码功能
This commit is contained in:
@@ -166,6 +166,28 @@ public class UserInfoController {
|
|||||||
return DocResponseJson.ok(password);
|
return DocResponseJson.ok(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AuthMan
|
||||||
|
@PostMapping("/updateSelfPwd")
|
||||||
|
public ResponseJson<Object> updateSelfPwd(String currentPwd, String newPwd) {
|
||||||
|
DocUserDetails currentUser = DocUserUtil.getCurrentUser();
|
||||||
|
// 检查密码是否正确
|
||||||
|
if (StringUtils.isBlank(currentPwd) || StringUtils.isBlank(newPwd)) {
|
||||||
|
return DocResponseJson.warn("密码不能为空");
|
||||||
|
}
|
||||||
|
UserInfo userInfo = userInfoService.getById(currentUser.getUserId());
|
||||||
|
String oldPasswordInput = DigestUtils.md5DigestAsHex(currentPwd.getBytes());
|
||||||
|
if (!Objects.equals(oldPasswordInput, userInfo.getPassword())) {
|
||||||
|
return DocResponseJson.warn("当前密码密码错误");
|
||||||
|
}
|
||||||
|
String newPassword = DigestUtils.md5DigestAsHex(newPwd.getBytes());
|
||||||
|
UserInfo userInfoUp = new UserInfo();
|
||||||
|
userInfoUp.setId(currentUser.getUserId());
|
||||||
|
userInfoUp.setPassword(newPassword);
|
||||||
|
userInfoUp.setUpdateTime(new Date());
|
||||||
|
userInfoService.updateById(userInfoUp);
|
||||||
|
return DocResponseJson.ok();
|
||||||
|
}
|
||||||
|
|
||||||
@AuthMan(DocAuthConst.USER_MANAGE)
|
@AuthMan(DocAuthConst.USER_MANAGE)
|
||||||
@PostMapping("/delete")
|
@PostMapping("/delete")
|
||||||
public ResponseJson<Object> delete(Long id) {
|
public ResponseJson<Object> delete(Long id) {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ export default {
|
|||||||
},
|
},
|
||||||
getSelfUserInfo: data => {
|
getSelfUserInfo: data => {
|
||||||
return request({url: '/user/info/selfInfo', method: 'post', data: Qs.stringify(data)});
|
return request({url: '/user/info/selfInfo', method: 'post', data: Qs.stringify(data)});
|
||||||
|
},
|
||||||
|
updateSelfPwd: data => {
|
||||||
|
return request({url: '/user/info/updateSelfPwd', method: 'post', data: Qs.stringify(data)});
|
||||||
},
|
},
|
||||||
selfInfoWithAuth: data => {
|
selfInfoWithAuth: data => {
|
||||||
return request({url: '/user/info/selfInfoWithAuth', method: 'post', data: Qs.stringify(data)});
|
return request({url: '/user/info/selfInfoWithAuth', method: 'post', data: Qs.stringify(data)});
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="my-info-vue">
|
<div class="my-info-vue">
|
||||||
<el-breadcrumb separator-class="el-icon-arrow-right" style="padding: 20px 10px;">
|
|
||||||
<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
|
|
||||||
<el-breadcrumb-item>我的信息</el-breadcrumb-item>
|
|
||||||
</el-breadcrumb>
|
|
||||||
<div style="margin: 0 auto;max-width: 1000px;">
|
<div style="margin: 0 auto;max-width: 1000px;">
|
||||||
<el-card class="box-card">
|
<el-card class="box-card">
|
||||||
<div slot="header" class="clearfix">我的信息</div>
|
<div slot="header" class="clearfix">
|
||||||
|
<el-row>
|
||||||
|
<el-col :span="12" style="line-height: 40px;">我的信息</el-col>
|
||||||
|
<el-col :span="12" style="text-align: right;">
|
||||||
|
<el-button type="primary" @click="showUpdatePasswordDialog"><i class="el-icon-edit"></i> 修改密码</el-button>
|
||||||
|
</el-col>
|
||||||
|
</el-row>
|
||||||
|
</div>
|
||||||
<el-form class="search-form-box" label-width="100px">
|
<el-form class="search-form-box" label-width="100px">
|
||||||
<el-form-item label="账号:">{{userInfo.userNo}}</el-form-item>
|
<el-form-item label="账号:">{{userInfo.userNo}}</el-form-item>
|
||||||
<el-form-item label="用户名:">{{userInfo.userName}}</el-form-item>
|
<el-form-item label="用户名:">{{userInfo.userName}}</el-form-item>
|
||||||
@@ -17,6 +20,22 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
</el-card>
|
</el-card>
|
||||||
</div>
|
</div>
|
||||||
|
<el-dialog title="修改密码" :visible.sync="updatePasswordDialogVisible" width="500px">
|
||||||
|
<el-form label-width="120px" :model="updatePassword" status-icon :rules="updatePasswordRules" ref="passwordForm">
|
||||||
|
<el-form-item label="当前密码" prop="currentPwd">
|
||||||
|
<el-input type="password" v-model="updatePassword.currentPwd" placeholder="请输入当前密码"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="新密码" prop="newPwd">
|
||||||
|
<el-input type="password" v-model="updatePassword.newPwd" placeholder="请输入新密码"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="确认新密码" prop="repeatPwd">
|
||||||
|
<el-input type="password" v-model="updatePassword.repeatPwd" placeholder="请再次输入新密码"></el-input>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item>
|
||||||
|
<el-button type="primary" @click="submitUpdatePasswordForm">修改密码</el-button>
|
||||||
|
</el-form-item>
|
||||||
|
</el-form>
|
||||||
|
</el-dialog>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -25,7 +44,18 @@
|
|||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
userInfo: {}
|
userInfo: {},
|
||||||
|
updatePasswordDialogVisible: false,
|
||||||
|
updatePassword: {
|
||||||
|
currentPwd: '',
|
||||||
|
newPwd: '',
|
||||||
|
repeatPwd: '',
|
||||||
|
},
|
||||||
|
updatePasswordRules: {
|
||||||
|
currentPwd: [{validator: this.validateCurrentPwd, trigger: 'blur'}],
|
||||||
|
newPwd: [{validator: this.validateNewPwd, trigger: 'blur'}],
|
||||||
|
repeatPwd: [{validator: this.validateRepeatPwd, trigger: 'blur'}],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
@@ -37,6 +67,54 @@
|
|||||||
this.userInfo = json.data;
|
this.userInfo = json.data;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
showUpdatePasswordDialog() {
|
||||||
|
this.updatePasswordDialogVisible = true;
|
||||||
|
},
|
||||||
|
submitUpdatePasswordForm() {
|
||||||
|
this.$refs.passwordForm.validate((valid) => {
|
||||||
|
if (!valid) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
consoleApi.updateSelfPwd(this.updatePassword).then(json => {
|
||||||
|
this.$message.success("修改成功!请重新登录");
|
||||||
|
setTimeout(() => {
|
||||||
|
consoleApi.userLogout().then(() => {
|
||||||
|
location.reload();
|
||||||
|
}).catch(e => {
|
||||||
|
console.log("退出登录失败", e);
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
validateCurrentPwd(rule, value, callback) {
|
||||||
|
if (value === '') {
|
||||||
|
callback(new Error('请输入密码'));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validateNewPwd(rule, value, callback) {
|
||||||
|
if (value === '') {
|
||||||
|
callback(new Error('请输入新密码'));
|
||||||
|
} else {
|
||||||
|
if (this.updatePassword.newPwd !== '') {
|
||||||
|
this.$refs.passwordForm.validateField('repeatPwd');
|
||||||
|
}
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validateRepeatPwd(rule, value, callback) {
|
||||||
|
if (value === '') {
|
||||||
|
callback(new Error('请再次输入新密码'));
|
||||||
|
} else {
|
||||||
|
if (this.updatePassword.repeatPwd !== this.updatePassword.newPwd) {
|
||||||
|
callback(new Error('两次输入的密码不一致'));
|
||||||
|
} else {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user