From b5ccb1636fc0efb0ea9d87c38995fee14cfd45d3 Mon Sep 17 00:00:00 2001
From: AlphaWu <wp@zafu.edu.cn>
Date: 星期日, 20 八月 2023 15:50:24 +0800
Subject: [PATCH] 修正Database拼写错误。

---
 src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java |   32 +++++++++++++++++++-------------
 1 files changed, 19 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 2b44dd7..5ffb02c
--- 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;
@@ -11,24 +12,21 @@
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 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.tags.Tag;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 import org.springframework.security.authentication.AuthenticationManager;
 import org.springframework.util.DigestUtils;
 import org.springframework.util.ObjectUtils;
-import org.springframework.util.StringUtils;
 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 {
@@ -43,11 +41,14 @@
     private IRoleService roleService;
 
     @GetMapping("/login")
-    @Operation(summary = "鐧诲綍")
+    @PostMapping("/login")
+    @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) {
@@ -55,9 +56,14 @@
         }
         if (user == null) {
             throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐢ㄦ埛鍚嶆垨瀵嗙爜閿欒");
+        }else {
+            String jwt = JwtUtils.createToken(username, password, user.getRole().getId());
+            response.setHeader(JwtUtils.getHeader(), jwt);
+            user.setAccessToken(jwt);
         }
         return user;
     }
+
 
     @PostMapping("/changePassword")
     @Operation(summary = "淇敼瀵嗙爜")
@@ -77,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);
             }
@@ -89,7 +95,7 @@
 
 
     @PostMapping("/add")
-    @Operation(summary = "鍋滄瑙嗛鍥炴斁")
+    @Operation(summary = "娣诲姞鐢ㄦ埛")
     @Parameter(name = "username", description = "鐢ㄦ埛鍚�", required = true)
     @Parameter(name = "password", description = "瀵嗙爜锛堟湭md5鍔犲瘑鐨勫瘑鐮侊級", required = true)
     @Parameter(name = "roleId", description = "瑙掕壊ID", required = true)
@@ -124,8 +130,8 @@
         }
     }
 
-    @DeleteMapping("/鍒犻櫎鐢ㄦ埛")
-    @Operation(summary = "鍋滄瑙嗛鍥炴斁")
+    @DeleteMapping("/delete")
+    @Operation(summary = "鍒犻櫎鐢ㄦ埛")
     @Parameter(name = "id", description = "鐢ㄦ埛Id", required = true)
     public void delete(@RequestParam Integer id){
         // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛id

--
Gitblit v1.8.0