| | |
| | | } |
| | | |
| | | @OperationLog("Reset Password") |
| | | @PostMapping("/auth/password") |
| | | @PostMapping("/auth/reset/password") |
| | | public R resetPassword(@RequestBody UpdatePasswordParam param) { |
| | | if (Cools.isEmpty(param.getOldPassword(), param.getPassword())) { |
| | | if (Cools.isEmpty(param.getOldPassword(), param.getNewPassword())) { |
| | | return R.error("Parameters Cannot Be Empty"); |
| | | } |
| | | Long userId = getLoginUserId(); |
| | |
| | | return R.error("Please Login First"); |
| | | } |
| | | if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) { |
| | | return R.error("The Origin Password Was Incorrect"); |
| | | return R.parse("408-The Current Password Was Incorrect"); |
| | | } |
| | | User user = new User(); |
| | | user.setId(userId); |
| | | user.setPassword(userService.encodePassword(param.getPassword())); |
| | | user.setPassword(userService.encodePassword(param.getNewPassword())); |
| | | if (userService.updateById(user)) { |
| | | return R.ok("Update Success"); |
| | | return R.ok("Reset Password Success"); |
| | | } |
| | | return R.error("Update Fail"); |
| | | return R.error("Reset Password Fail"); |
| | | } |
| | | |
| | | |