From 9bd588957a08ae3fa574fddacc2eebc5ba79553b Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期三, 28 六月 2023 20:27:25 +0800 Subject: [PATCH] 修复获取pushKey --- src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java index d23b03c..090cf33 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java @@ -24,6 +24,7 @@ import javax.security.sasl.AuthenticationException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.time.LocalDateTime; import java.util.List; @Tag(name = "鐢ㄦ埛绠$悊") @@ -57,7 +58,7 @@ if (user == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒"); }else { - String jwt = JwtUtils.createToken(username, password); + String jwt = JwtUtils.createToken(username, password, user.getRole().getId()); response.setHeader(JwtUtils.getHeader(), jwt); user.setAccessToken(jwt); } @@ -83,8 +84,8 @@ if (user == null) { throw new ControllerException(ErrorCode.ERROR100); } - int userId = SecurityUtils.getUserId(); - boolean result = userService.changePassword(userId, DigestUtils.md5DigestAsHex(password.getBytes())); + //int userId = SecurityUtils.getUserId(); + boolean result = userService.changePassword(user.getId(), DigestUtils.md5DigestAsHex(password.getBytes())); if (!result) { throw new ControllerException(ErrorCode.ERROR100); } @@ -205,4 +206,17 @@ } } } + + @PostMapping("/userInfo") + @Operation(summary = "绠$悊鍛樹慨鏀规櫘閫氱敤鎴峰瘑鐮�") + public LoginUser getUserInfo() { + // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id + LoginUser userInfo = SecurityUtils.getUserInfo(); + + if (userInfo == null) { + throw new ControllerException(ErrorCode.ERROR100); + } + User user = userService.getUser(userInfo.getUsername(), userInfo.getPassword()); + return new LoginUser(user, LocalDateTime.now()); + } } -- Gitblit v1.8.0