From e932a9b824b93a4a0365e11f1e02775b10c0b045 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: 星期五, 01 三月 2024 10:55:49 +0800 Subject: [PATCH] Merge branch '2.6.9' into wvp-28181-2.0 --- src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java | 44 +++++++++++++++----------------------------- 1 files changed, 15 insertions(+), 29 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 old mode 100644 new mode 100755 index 035f380..9d55206 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java @@ -14,6 +14,7 @@ import com.github.pagehelper.PageInfo; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; @@ -42,7 +43,9 @@ @GetMapping("/login") @PostMapping("/login") - @Operation(summary = "鐧诲綍") + @Operation(summary = "鐧诲綍", description = "鐧诲綍鎴愬姛鍚庤繑鍥濧ccessToken锛� 鍙互浠庤繑鍥炲�艰幏鍙栧埌涔熷彲浠ヤ粠鍝嶅簲澶翠腑鑾峰彇鍒帮紝" + + "鍚庣画鐨勮姹傞渶瑕佹坊鍔犺姹傚ご 'access-token'鎴栬�呮斁鍦ㄥ弬鏁伴噷") + @Parameter(name = "username", description = "鐢ㄦ埛鍚�", required = true) @Parameter(name = "password", description = "瀵嗙爜锛�32浣峬d5鍔犲瘑锛�", required = true) public LoginUser login(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password){ @@ -55,33 +58,16 @@ if (user == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒"); }else { - String jwt = JwtUtils.createToken(username, password); + String jwt = JwtUtils.createToken(username); response.setHeader(JwtUtils.getHeader(), jwt); + user.setAccessToken(jwt); } return user; } -// @GetMapping("/logout") -// @PostMapping("/logout") -// @Operation(summary = "鐧诲嚭") -// public LoginUser logout(){ -// LoginUser user; -// try { -// user = SecurityUtils.login(username, password, authenticationManager); -// } catch (AuthenticationException e) { -// throw new ControllerException(ErrorCode.ERROR100.getCode(), e.getMessage()); -// } -// if (user == null) { -// throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒"); -// }else { -// String jwt = JwtUtils.createToken(username, password); -// response.setHeader(JwtUtils.getHeader(), jwt); -// } -// return user; -// } @PostMapping("/changePassword") - @Operation(summary = "淇敼瀵嗙爜") + @Operation(summary = "淇敼瀵嗙爜", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "username", description = "鐢ㄦ埛鍚�", required = true) @Parameter(name = "oldpassword", description = "鏃у瘑鐮侊紙宸瞞d5鍔犲瘑鐨勫瘑鐮侊級", required = true) @Parameter(name = "password", description = "鏂板瘑鐮侊紙鏈猰d5鍔犲瘑鐨勫瘑鐮侊級", required = true) @@ -98,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); } @@ -110,7 +96,7 @@ @PostMapping("/add") - @Operation(summary = "娣诲姞鐢ㄦ埛") + @Operation(summary = "娣诲姞鐢ㄦ埛", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "username", description = "鐢ㄦ埛鍚�", required = true) @Parameter(name = "password", description = "瀵嗙爜锛堟湭md5鍔犲瘑鐨勫瘑鐮侊級", required = true) @Parameter(name = "roleId", description = "瑙掕壊ID", required = true) @@ -146,7 +132,7 @@ } @DeleteMapping("/delete") - @Operation(summary = "鍒犻櫎鐢ㄦ埛") + @Operation(summary = "鍒犻櫎鐢ㄦ埛", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "id", description = "鐢ㄦ埛Id", required = true) public void delete(@RequestParam Integer id){ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id @@ -162,7 +148,7 @@ } @GetMapping("/all") - @Operation(summary = "鏌ヨ鐢ㄦ埛") + @Operation(summary = "鏌ヨ鐢ㄦ埛", security = @SecurityRequirement(name = JwtUtils.HEADER)) public List<User> all(){ // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id return userService.getAllUsers(); @@ -176,7 +162,7 @@ * @return 鍒嗛〉鐢ㄦ埛鍒楄〃 */ @GetMapping("/users") - @Operation(summary = "鍒嗛〉鏌ヨ鐢ㄦ埛") + @Operation(summary = "鍒嗛〉鏌ヨ鐢ㄦ埛", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "page", description = "褰撳墠椤�", required = true) @Parameter(name = "count", description = "姣忛〉鏌ヨ鏁伴噺", required = true) public PageInfo<User> users(int page, int count) { @@ -184,7 +170,7 @@ } @RequestMapping("/changePushKey") - @Operation(summary = "淇敼pushkey") + @Operation(summary = "淇敼pushkey", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "userId", description = "鐢ㄦ埛Id", required = true) @Parameter(name = "pushKey", description = "鏂扮殑pushKey", required = true) public void changePushKey(@RequestParam Integer userId,@RequestParam String pushKey) { @@ -202,7 +188,7 @@ } @PostMapping("/changePasswordForAdmin") - @Operation(summary = "绠$悊鍛樹慨鏀规櫘閫氱敤鎴峰瘑鐮�") + @Operation(summary = "绠$悊鍛樹慨鏀规櫘閫氱敤鎴峰瘑鐮�", security = @SecurityRequirement(name = JwtUtils.HEADER)) @Parameter(name = "adminId", description = "绠$悊鍛榠d", required = true) @Parameter(name = "userId", description = "鐢ㄦ埛id", required = true) @Parameter(name = "password", description = "鏂板瘑鐮侊紙鏈猰d5鍔犲瘑鐨勫瘑鐮侊級", required = true) -- Gitblit v1.8.0