| | |
| | | Long tenantId = param.getTenantId(); |
| | | User user = userService.getByUsername(username, tenantId); |
| | | if (user == null) { |
| | | return R.error("账号不存在"); |
| | | return R.error("Username Does Not Exist"); |
| | | } |
| | | if (!user.getStatus().equals(1)) { |
| | | return R.error("账号被冻结"); |
| | | return R.error("Account Frozen"); |
| | | } |
| | | if (!userService.comparePassword(user.getPassword(), param.getPassword())) { |
| | | return R.error("密码错误"); |
| | | return R.error("Wrong Password"); |
| | | } |
| | | String accessToken = JwtUtil.buildToken(new JwtSubject(username, user.getTenantId()), |
| | | configProperties.getTokenExpireTime(), configProperties.getTokenKey()); |
| | | userLoginService.saveAsync(user.getId(), accessToken, UserLogin.TYPE_LOGIN, tenantId, null, request); |
| | | return R.ok("登录成功").add(new LoginResult(accessToken, user)); |
| | | return R.ok("Login Success").add(new LoginResult(accessToken, user)); |
| | | } |
| | | |
| | | @GetMapping("/auth/user") |
| | |
| | | if (userService.updateById(user)) { |
| | | return R.ok().add(userService.getByIdRel(user.getId())); |
| | | } |
| | | return R.error("保存失败"); |
| | | return R.error("Save Fail"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('sys:auth:password')") |
| | |
| | | @PutMapping("/auth/password") |
| | | public R updatePassword(@RequestBody UpdatePasswordParam param) { |
| | | if (Cools.isEmpty(param.getOldPassword(), param.getPassword())) { |
| | | return R.error("参数不能为空"); |
| | | return R.error("Parameters Cannot Be Empty"); |
| | | } |
| | | Long userId = getLoginUserId(); |
| | | if (userId == null) { |
| | | return R.error("未登录"); |
| | | return R.error("Please Login First"); |
| | | } |
| | | if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) { |
| | | return R.error("原密码输入不正确"); |
| | | return R.error("The Origin Password Was Incorrect"); |
| | | } |
| | | User user = new User(); |
| | | user.setId(userId); |
| | | user.setPassword(userService.encodePassword(param.getPassword())); |
| | | if (userService.updateById(user)) { |
| | | return R.ok("修改成功"); |
| | | return R.ok("Update Success"); |
| | | } |
| | | return R.error("修改失败"); |
| | | return R.error("Update Fail"); |
| | | } |
| | | |
| | | } |