修改密码、重置密码bug修改、给超级管理员所有按钮权限
This commit is contained in:
parent
ae8a71ad78
commit
41b21ee920
@ -191,14 +191,27 @@ public class LoginController {
|
||||
}
|
||||
|
||||
@Log(module = "用户登录", value = "更改用户密码")
|
||||
@GetMapping("/updatePassword")
|
||||
@RequestMapping(value = "/updatePassword",
|
||||
method = {RequestMethod.POST, RequestMethod.PUT})
|
||||
@Operation(summary = "更改用户密码")
|
||||
@ResponseBody
|
||||
public ResponseResult updatePassword(@RequestBody SysUser user) throws Exception {
|
||||
if (user == null || StrUtil.isBlank(user.getId()) || StrUtil.isBlank(
|
||||
user.getPassword())) {
|
||||
return ResponseResult.error("参数为空");
|
||||
}
|
||||
SysUser dbUser = userService.getById(user.getId());
|
||||
if (dbUser == null) {
|
||||
return ResponseResult.error("用户不存在");
|
||||
}
|
||||
// 密码解密
|
||||
String password = RsaUtils.decryptByPrivateKey(privateKey,
|
||||
user.getPassword());
|
||||
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
|
||||
if (StrUtil.isNotBlank(dbUser.getPassword()) && passwordEncoder.matches(
|
||||
password, dbUser.getPassword())) {
|
||||
return ResponseResult.error("新密码不能与旧密码一致");
|
||||
}
|
||||
String cryptPassword = passwordEncoder.encode(password);
|
||||
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.set("password", cryptPassword);
|
||||
|
||||
@ -269,6 +269,7 @@ public class SysRoleController {
|
||||
*sysRole 角色对象
|
||||
* 返回值说明: 是否修改成功
|
||||
***********************************/
|
||||
@Log(module = "系统角色", value = "更新角色信息")
|
||||
@PostMapping("/updateById")
|
||||
@Operation(summary = "更新角色信息")
|
||||
@ResponseBody
|
||||
|
||||
@ -40,6 +40,8 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
||||
|
||||
List<String> selectPermsByUserId(String userId);
|
||||
|
||||
List<String> selectAllPerms();
|
||||
|
||||
//List<SysMenu> selectMenuByUserId(String userId);
|
||||
List<Map<String,Object>> selectMenuByUserId(String userId);
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import com.yfd.platform.datasource.DataSource;
|
||||
import com.yfd.platform.system.domain.LoginUser;
|
||||
import com.yfd.platform.system.domain.SysUser;
|
||||
import com.yfd.platform.system.mapper.SysMenuMapper;
|
||||
import com.yfd.platform.system.mapper.SysUserMapper;
|
||||
import com.yfd.platform.system.service.IUserService;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
@ -32,6 +33,9 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
@Resource
|
||||
private SysMenuMapper sysMenuMapper;
|
||||
|
||||
@Resource
|
||||
private SysUserMapper sysUserMapper;
|
||||
|
||||
@Override
|
||||
@DataSource(name = "master")
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
@ -42,9 +46,13 @@ public class UserDetailsServiceImpl implements UserDetailsService {
|
||||
if (ObjectUtil.isEmpty(user)) {
|
||||
throw new RuntimeException("用户账号不存在!");
|
||||
}
|
||||
//Todo 根据用户查询权限信息 添加到LoginUser中
|
||||
List<String> permissions =
|
||||
sysMenuMapper.selectPermsByUserId(user.getId());
|
||||
String level = sysUserMapper.getMaxLevel(user.getId());
|
||||
List<String> permissions;
|
||||
if ("1".equals(level)) {
|
||||
permissions = sysMenuMapper.selectAllPerms();
|
||||
} else {
|
||||
permissions = sysMenuMapper.selectPermsByUserId(user.getId());
|
||||
}
|
||||
|
||||
//封装成UserDetails对象返回
|
||||
return new LoginUser(user,permissions);
|
||||
|
||||
@ -386,8 +386,8 @@ public class UserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impleme
|
||||
String level = sysUserMapper.getMaxLevel(id);
|
||||
//判断是否获取级别
|
||||
if (StrUtil.isNotEmpty(level)) {
|
||||
//判断当前用户级别 管理员及以上权限
|
||||
if (Integer.parseInt(level) <= 2) {
|
||||
//判断当前用户级别 管理员及以上权限 (1超级管理员,不能修改,其他(2-3)可以修改)
|
||||
if (Integer.parseInt(level) >= 2) {
|
||||
UpdateWrapper<SysUser> updateWrapper = new UpdateWrapper<>();
|
||||
//根据id 修改密码,密码修改时间,最近修改者,最近修改日期 将密码修改为 123456
|
||||
String cryptPassword = passwordEncoder.encode("123456");
|
||||
|
||||
@ -27,6 +27,16 @@
|
||||
AND permission != ''
|
||||
</select>
|
||||
|
||||
<select id="selectAllPerms" resultType="java.lang.String">
|
||||
SELECT DISTINCT
|
||||
permission
|
||||
FROM
|
||||
sys_menu
|
||||
WHERE
|
||||
permission IS NOT NULL
|
||||
AND permission != ''
|
||||
</select>
|
||||
|
||||
<select id="selectMenuByUserId"
|
||||
resultType="Map">
|
||||
SELECT
|
||||
|
||||
Loading…
Reference in New Issue
Block a user