21 lines
516 B
Python
21 lines
516 B
Python
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
from pydantic import BaseModel
|
|
|
|
from bsition.api.jwt import write_token
|
|
from bsition.backend.postgres import get_user_by_username
|
|
|
|
auth_routes = APIRouter()
|
|
|
|
|
|
class User(BaseModel):
|
|
username: str
|
|
|
|
|
|
@auth_routes.post("/login")
|
|
def login(user: User):
|
|
if get_user_by_username(user.username) is not None:
|
|
return write_token(user.dict())
|
|
else:
|
|
return JSONResponse(content={"message": "User not found"}, status_code=404)
|