From 8874c90db2c238fa4c55df491675fe7fec9d93b2 Mon Sep 17 00:00:00 2001
From: fine <54142345+criver31@users.noreply.github.com>
Date: 星期二, 09 一月 2024 11:45:30 +0800
Subject: [PATCH] Merge branch '648540858:wvp-28181-2.0' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java | 30 +++++++++++++++++-------------
1 files changed, 17 insertions(+), 13 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 826dd51..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;
@@ -27,7 +28,6 @@
import java.util.List;
@Tag(name = "鐢ㄦ埛绠$悊")
-
@RestController
@RequestMapping("/api/user")
public class UserController {
@@ -43,11 +43,13 @@
@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){
- LoginUser user = null;
+ LoginUser user;
try {
user = SecurityUtils.login(username, password, authenticationManager);
} catch (AuthenticationException e) {
@@ -56,14 +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;
}
+
@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)
@@ -80,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);
}
@@ -92,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)
@@ -128,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
@@ -144,7 +148,7 @@
}
@GetMapping("/all")
- @Operation(summary = "鏌ヨ鐢ㄦ埛")
+ @Operation(summary = "鏌ヨ鐢ㄦ埛", security = @SecurityRequirement(name = JwtUtils.HEADER))
public List<User> all(){
// 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id
return userService.getAllUsers();
@@ -158,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) {
@@ -166,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) {
@@ -184,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