Coverage for view / web / routes / auth.py: 100%
17 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-04 15:08 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-04 15:08 +0000
1"""
2인증 관련 API 엔드포인트 (login.html).
3"""
4from fastapi import APIRouter, Form, Response
5from fastapi.responses import JSONResponse
6from view.web.api_common import _get_ctx
8router = APIRouter()
11@router.post("/auth/login")
12async def login(response: Response, username: str = Form(...), password: str = Form(...)):
13 ctx = _get_ctx()
14 auth_config = ctx.full_config.get("auth", {})
16 print(f"\n=== 로그인 시도 ===")
17 print(f"입력 ID: {username} / PW: {password}")
18 print(f"설정 ID: {auth_config.get('username')} / PW: {auth_config.get('password')}")
19 print(f"==================\n")
21 if username == auth_config.get("username") and password == auth_config.get("password"):
22 response = JSONResponse(content={"success": True})
23 # 쿠키 설정
24 response.set_cookie(
25 key="access_token",
26 value=auth_config.get("secret_key"),
27 httponly=True,
28 samesite="lax" # 로컬 테스트 시 안정성 위함
29 )
30 return response
32 return JSONResponse(content={"success": False, "msg": "아이디 또는 비밀번호가 틀렸습니다."}, status_code=401)