| | |
| | | return toAjax(result); |
| | | } |
| | | |
| | | /** |
| | | * 重置操作密码 |
| | | */ |
| | | @RequiresPermissions(value = {"/systemUserManagement/reset_passwords"}, logical = Logical.OR) |
| | | @Log(title = "用户管理", businessType = BusinessType.UPDATE) |
| | | @PutMapping("/resetOperationPwd") |
| | | @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); |
| | | if (user == null) { |
| | | return AjaxResult.error("用户不存在"); |
| | | } |
| | | userService.checkUserAllowed(user); |
| | | userService.checkUserDataScope(userId); |
| | | |
| | | 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()); |
| | | 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))) { |
| | | return null; |