14 lines
514 B
Python
14 lines
514 B
Python
from fastapi import APIRouter, HTTPException, status
|
|
|
|
from backend.auth import create_access_token, verify_password
|
|
from backend.schemas import LoginRequest, Token
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/login", response_model=Token)
|
|
def login(payload: LoginRequest) -> Token:
|
|
if not verify_password(payload.username, payload.password):
|
|
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="用户名或密码错误")
|
|
return Token(access_token=create_access_token(payload.username))
|