修改部分接口,方便前后端链接
Change-Id: Icce71f5085084a4185cb11fe3313d618dfb01177
diff --git a/src/main/java/com/pt/controller/AdminController.java b/src/main/java/com/pt/controller/AdminController.java
index 22e2b86..8af5b56 100644
--- a/src/main/java/com/pt/controller/AdminController.java
+++ b/src/main/java/com/pt/controller/AdminController.java
@@ -6,11 +6,7 @@
import com.pt.service.AdminService;
import com.pt.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
import org.springframework.http.ResponseEntity;
import java.util.HashMap;
@@ -25,18 +21,18 @@
private AdminService adminService;
@PostMapping("/login")
- public ResponseEntity<?> loginAdmin(@RequestParam("username") String username,
- @RequestParam("password") String password) {
+ public ResponseEntity<?> loginAdmin(@RequestBody Map<String, String> request) {
+ String username = request.get("username");
+ String password = request.get("password");
+
Map<String, Object> ans = new HashMap<>();
Admin admin = adminService.findByUsernameAndPassword(username, password);
if (admin != null) {
- ans.put("result", "Login successful");
- ans.put("data", Map.of(
- "token", JWTUtils.generateToken(username, Constants.UserRole.ADMIN, (int)1.2e8)
- ));
+ ans.put("message", "Login successful");
+ ans.put("data", JWTUtils.generateToken(username, Constants.UserRole.ADMIN, Constants.DEFAULT_EXPIRE_TIME));
return ResponseEntity.ok().body(ans);
} else {
- ans.put("result", "Invalid username or password");
+ ans.put("message", "Invalid username or password");
return ResponseEntity.badRequest().body(ans);
}
}