feat[litemall-admin, litemall-admin-api]: 管理员后台的管理员密码修改页面
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package org.linlinjava.litemall.admin.web;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.linlinjava.litemall.admin.annotation.LoginAdmin;
|
||||
import org.linlinjava.litemall.core.util.JacksonUtil;
|
||||
import org.linlinjava.litemall.core.util.ResponseUtil;
|
||||
import org.linlinjava.litemall.core.util.bcrypt.BCryptPasswordEncoder;
|
||||
import org.linlinjava.litemall.db.domain.LitemallAdmin;
|
||||
import org.linlinjava.litemall.db.service.LitemallAdminService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/profile")
|
||||
@Validated
|
||||
public class AdminProfileController {
|
||||
private final Log logger = LogFactory.getLog(AdminProfileController.class);
|
||||
|
||||
@Autowired
|
||||
private LitemallAdminService adminService;
|
||||
|
||||
@PostMapping("/password")
|
||||
public Object create(@LoginAdmin Integer adminId, @RequestBody String body){
|
||||
if(adminId == null){
|
||||
return ResponseUtil.unlogin();
|
||||
}
|
||||
|
||||
String oldPassword = JacksonUtil.parseString(body, "oldPassword");
|
||||
String newPassword = JacksonUtil.parseString(body, "newPassword");
|
||||
if(StringUtils.isEmpty(oldPassword)){
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
if(StringUtils.isEmpty(newPassword)){
|
||||
return ResponseUtil.badArgument();
|
||||
}
|
||||
|
||||
LitemallAdmin admin = adminService.findAdmin(adminId);
|
||||
|
||||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
|
||||
if(!encoder.matches(oldPassword, admin.getPassword())){
|
||||
return ResponseUtil.fail(405, "账号密码不对");
|
||||
}
|
||||
|
||||
String encodedNewPassword = encoder.encode(newPassword);
|
||||
admin.setPassword(encodedNewPassword);
|
||||
|
||||
adminService.updateById(admin);
|
||||
return ResponseUtil.ok();
|
||||
}
|
||||
|
||||
}
|
||||
9
litemall-admin/src/api/profile.js
Normal file
9
litemall-admin/src/api/profile.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export function changePassword(data) {
|
||||
return request({
|
||||
url: '/profile/password',
|
||||
method: 'post',
|
||||
data
|
||||
})
|
||||
}
|
||||
@@ -152,6 +152,14 @@ export const asyncRouterMap = [
|
||||
{ path: 'goods', component: _import('stat/goods'), name: 'statGoods', meta: { title: '商品统计', noCache: true }}
|
||||
]
|
||||
},
|
||||
|
||||
{
|
||||
path: '/profile',
|
||||
component: Layout,
|
||||
redirect: 'noredirect',
|
||||
children: [
|
||||
{ path: 'password', component: _import('profile/password'), name: 'password', meta: { title: '修改密码', noCache: true }}
|
||||
],
|
||||
hidden: true
|
||||
},
|
||||
{ path: '*', redirect: '/404', hidden: true }
|
||||
]
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
主页
|
||||
</router-link>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item>
|
||||
<el-dropdown-item divided>
|
||||
<a target='_blank' href="https://github.com/linlinjava/litemall">
|
||||
GitHub
|
||||
</a>
|
||||
@@ -31,6 +31,11 @@
|
||||
码云
|
||||
</a>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided>
|
||||
<router-link to="/profile/password">
|
||||
密码修改
|
||||
</router-link>
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item divided>
|
||||
<span @click="logout" style="display:block;">退出登录</span>
|
||||
</el-dropdown-item>
|
||||
|
||||
95
litemall-admin/src/views/profile/password.vue
Normal file
95
litemall-admin/src/views/profile/password.vue
Normal file
@@ -0,0 +1,95 @@
|
||||
<template>
|
||||
<div class="app-container calendar-list-container">
|
||||
<el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="100px" style='width: 400px; margin-left:50px;'>
|
||||
<el-form-item label="原密码" prop="oldPassword">
|
||||
<el-input type="password" v-model="dataForm.oldPassword"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="新密码" prop="newPassword">
|
||||
<el-input type="password" v-model="dataForm.newPassword" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="确认密码" prop="newPassword2">
|
||||
<el-input type="password" v-model="dataForm.newPassword2" auto-complete="off"></el-input>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div style='margin-left:100px;'>
|
||||
<el-button @click="cancel">取消</el-button>
|
||||
<el-button type="primary" @click="change">确定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { changePassword } from '@/api/profile'
|
||||
|
||||
export default {
|
||||
name: 'ChangePassword',
|
||||
data() {
|
||||
var validatePass = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请输入密码'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
var validatePass2 = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请再次输入密码'))
|
||||
} else if (value !== this.dataForm.newPassword) {
|
||||
callback(new Error('两次输入密码不一致!'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
return {
|
||||
dataForm: {
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
newPassword2: ''
|
||||
},
|
||||
rules: {
|
||||
oldPassword: [
|
||||
{ required: true, message: '旧密码不能为空', trigger: 'blur' }
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: '新密码不能为空', trigger: 'blur' },
|
||||
{ validator: validatePass, trigger: 'blur' }
|
||||
],
|
||||
newPassword2: [
|
||||
{ required: true, message: '确认密码不能为空', trigger: 'blur' },
|
||||
{ validator: validatePass2, trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
cancel() {
|
||||
this.dataForm = {
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
newPassword2: ''
|
||||
}
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].clearValidate()
|
||||
})
|
||||
},
|
||||
change() {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (!valid) {
|
||||
return
|
||||
}
|
||||
changePassword(this.dataForm).then(response => {
|
||||
this.$notify.success({
|
||||
title: '成功',
|
||||
message: '修改密码成功'
|
||||
})
|
||||
}).catch(response => {
|
||||
this.$notify.error({
|
||||
title: '失败',
|
||||
message: response.data.errmsg
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -22,6 +22,11 @@ public class LitemallAdminService {
|
||||
return adminMapper.selectByExample(example);
|
||||
}
|
||||
|
||||
public LitemallAdmin findAdmin(Integer id) {
|
||||
return adminMapper.selectByPrimaryKey(id);
|
||||
|
||||
}
|
||||
|
||||
private final Column[] result = new Column[]{Column.id, Column.username, Column.avatar};
|
||||
public List<LitemallAdmin> querySelective(String username, Integer page, Integer limit, String sort, String order) {
|
||||
LitemallAdminExample example = new LitemallAdminExample();
|
||||
@@ -67,4 +72,5 @@ public class LitemallAdminService {
|
||||
public LitemallAdmin findById(Integer id) {
|
||||
return adminMapper.selectByPrimaryKeySelective(id, result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user