dev
This commit is contained in:
23
domain-api/app/api/routes/auth.py
Normal file
23
domain-api/app/api/routes/auth.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
from app.core.config import settings
|
||||
from app.schemas.auth import LoginRequest
|
||||
from app.schemas.common import ApiResponse
|
||||
|
||||
router = APIRouter(tags=["auth"])
|
||||
|
||||
|
||||
@router.post("/auth/login", response_model=ApiResponse)
|
||||
def login(payload: LoginRequest) -> ApiResponse:
|
||||
if payload.username != settings.admin_username or payload.password != settings.admin_password:
|
||||
return ApiResponse(code=1, message="账号或密码错误", data=None)
|
||||
token = f"domain-web-token-{payload.username}"
|
||||
return ApiResponse(
|
||||
data={
|
||||
"access_token": token,
|
||||
"user": {
|
||||
"username": payload.username,
|
||||
"display_name": "管理员" if payload.username == "admin" else payload.username,
|
||||
},
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user