| | |
| | | @ApiOperation(value = "重置操作密码", tags = {"管理后台-系统用户管理"}) |
| | | public AjaxResult resetOperationPwd(@RequestBody Map<String, Object> params) { |
| | | Long userId = parseLong(params.get("userId")); |
| | | String operationPassword = parseString(params.get("operationPassword")); |
| | | String code = parseString(params.get("code")); |
| | | if (userId == null) { |
| | | return AjaxResult.error("用户不存在"); |
| | | } |
| | | if (StringUtils.isEmpty(operationPassword)) { |
| | | return AjaxResult.error("请输入新操作密码"); |
| | | } |
| | | if (StringUtils.isEmpty(code)) { |
| | | return AjaxResult.error("请输入验证码"); |
| | | } |
| | | |
| | | SysUser user = userService.selectUserById(userId); |
| | |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(userId); |
| | | |
| | | user.setOperationPassword(SecurityUtils.encryptPassword("123456")); |
| | | String cacheCode = redisService.getCacheObject(RESET_PWD_CODE_KEY + userId); |
| | | if (StringUtils.isEmpty(cacheCode)) { |
| | | return AjaxResult.error("验证码已过期,请重新获取验证码"); |
| | | } |
| | | if (!code.equals(cacheCode)) { |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | |
| | | user.setOperationPassword(SecurityUtils.encryptPassword(operationPassword)); |
| | | user.setUpdateBy(SecurityUtils.getUsername()); |
| | | return toAjax(userService.updateUser(user)); |
| | | int result = userService.updateUser(user); |
| | | redisService.deleteObject(RESET_PWD_CODE_KEY + userId); |
| | | return toAjax(result); |
| | | } |
| | | private Long parseLong(Object value) { |
| | | if (value == null || StringUtils.isEmpty(String.valueOf(value))) { |