30 lines
897 B
Java
30 lines
897 B
Java
package com.zioinfo.cms.auth;
|
|
|
|
import com.zioinfo.cms.common.ApiResponse;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.Map;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/cms/auth")
|
|
@RequiredArgsConstructor
|
|
public class AuthController {
|
|
|
|
private final AuthService authService;
|
|
|
|
@PostMapping("/login")
|
|
public ApiResponse<Map<String, String>> login(@RequestBody LoginRequest req) {
|
|
String token = authService.login(req.username(), req.password());
|
|
return ApiResponse.ok(Map.of("token", token, "type", "Bearer"));
|
|
}
|
|
|
|
@GetMapping("/me")
|
|
public ApiResponse<Map<String, Object>> me(@RequestHeader("Authorization") String header) {
|
|
String token = header.replace("Bearer ", "");
|
|
return ApiResponse.ok(authService.me(token));
|
|
}
|
|
|
|
record LoginRequest(String username, String password) {}
|
|
}
|