feat: 登录接口改用RequestBody接收,Content-Type应为application/json
This commit is contained in:
parent
275ca89962
commit
98d938976b
@ -1,6 +1,7 @@
|
||||
package github.benjamin.equipreservebackend.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@ -12,4 +13,13 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
registry.addResourceHandler("/device_image/**")
|
||||
.addResourceLocations("file:" + System.getProperty("user.dir") + "/device_image/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOriginPatterns("*")
|
||||
.allowedMethods("*")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package github.benjamin.equipreservebackend.controller;
|
||||
|
||||
import github.benjamin.equipreservebackend.dto.LoginRequest;
|
||||
import github.benjamin.equipreservebackend.vo.LoginResponse;
|
||||
import github.benjamin.equipreservebackend.response.ResponseResult;
|
||||
import github.benjamin.equipreservebackend.entity.User;
|
||||
@ -8,6 +9,7 @@ import github.benjamin.equipreservebackend.service.UserService;
|
||||
import github.benjamin.equipreservebackend.utils.JwtUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@ -19,8 +21,8 @@ public class UserController {
|
||||
private final JwtUtil jwtUtil;
|
||||
|
||||
@PostMapping("/login")
|
||||
public ResponseResult<LoginResponse> login(String username, String password) {
|
||||
User user = userService.login(username, password);
|
||||
public ResponseResult<LoginResponse> login(@RequestBody LoginRequest request) {
|
||||
User user = userService.login(request.getUsername(), request.getPassword());
|
||||
SecurityUser securityUser = userService.loadSecurityUserById(user.getId());
|
||||
String token = jwtUtil.generateToken(securityUser);
|
||||
return ResponseResult.success(new LoginResponse(user.getId(), user.getName(), token));
|
||||
|
@ -0,0 +1,11 @@
|
||||
package github.benjamin.equipreservebackend.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class LoginRequest {
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user