From b4048fbe80dba8e7756ae557a15ab60b4f80a44b Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 04 四月 2023 09:09:07 +0800
Subject: [PATCH] 合并开源主线

---
 src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java |   21 +++++++++++++++------
 1 files changed, 15 insertions(+), 6 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 91c3cf5..37f9aba 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
@@ -1,6 +1,7 @@
 package com.genersoft.iot.vmp.vmanager.user;
 
 import com.genersoft.iot.vmp.conf.exception.ControllerException;
+import com.genersoft.iot.vmp.conf.security.JwtUtils;
 import com.genersoft.iot.vmp.conf.security.SecurityUtils;
 import com.genersoft.iot.vmp.conf.security.dto.LoginUser;
 import com.genersoft.iot.vmp.service.IRoleService;
@@ -21,10 +22,11 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.security.sasl.AuthenticationException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 @Tag(name  = "鐢ㄦ埛绠$悊")
-@CrossOrigin
 @RestController
 @RequestMapping("/api/user")
 public class UserController {
@@ -40,11 +42,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(@RequestParam String username, @RequestParam String password){
-        LoginUser user = null;
+    public LoginUser login(HttpServletRequest request, HttpServletResponse response, @RequestParam String username, @RequestParam String password){
+        LoginUser user;
         try {
             user = SecurityUtils.login(username, password, authenticationManager);
         } catch (AuthenticationException e) {
@@ -52,9 +56,14 @@
         }
         if (user == null) {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒");
+        }else {
+            String jwt = JwtUtils.createToken(username, password);
+            response.setHeader(JwtUtils.getHeader(), jwt);
+            user.setAccessToken(jwt);
         }
         return user;
     }
+
 
     @PostMapping("/changePassword")
     @Operation(summary = "淇敼瀵嗙爜")
@@ -74,8 +83,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);
             }

--
Gitblit v1.8.0