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