@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
public Result<?> changPassword(@RequestBody JSONObject json) {
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String oldpassword = json.getString("oldpassword");
String password = json.getString("password");
String confirmpassword = json.getString("confirmpassword");
return sysUserService.resetPassword(sysUser.getUsername(),oldpassword,password,confirmpassword);
}
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword);
@Override
@CacheEvict(value = {CacheConstant.SYS_USERS_CACHE}, allEntries = true)
public Result<?> resetPassword(String username, String oldpassword, String newpassword, String confirmpassword) {
SysUser user = userMapper.getUserByName(username);
String passwordEncode = PasswordUtil.encrypt(username, oldpassword, user.getSalt());
if (!user.getPassword().equals(passwordEncode)) {
return Result.error("旧密码输入错误!");
}
if (oConvertUtils.isEmpty(newpassword)) {
return Result.error("新密码不允许为空!");
}
if (!newpassword.equals(confirmpassword)) {
return Result.error("两次输入密码不一致!");
}
String password = PasswordUtil.encrypt(username, newpassword, user.getSalt());
this.userMapper.update(new SysUser().setPassword(password), new LambdaQueryWrapper<SysUser>().eq(SysUser::getId, user.getId()));
return Result.ok("密码重置成功!");
}
public SysUser getUserByName(@Param("username") String username);
<!-- 根据用户名查询 -->
<select id="getUserByName" resultType="org.jeecg.modules.system.entity.SysUser">
select * from sys_user where username = #{username} and del_flag = '0'
</select>