feat: 第一次上传

This commit is contained in:
2025-12-14 22:21:03 +08:00
commit 366ab0b2e8
19 changed files with 1008 additions and 0 deletions

38
routers/auth.py Normal file
View File

@@ -0,0 +1,38 @@
from fastapi import APIRouter, Request, Response
from fastapi.responses import JSONResponse, RedirectResponse
from models import User
from services.services import XBXS
from starlette.templating import Jinja2Templates
router = APIRouter()
templates = Jinja2Templates(directory="templates")
@router.get("/")
async def index(request: Request):
token = request.cookies.get("xbxs_token")
if token:
return RedirectResponse("/home")
return templates.TemplateResponse("login.html", {"request": request})
@router.post("/login")
async def login(user: User, response: Response):
xbxs = XBXS()
result = await xbxs.login(username=user.username, password=user.password)
token = result.get("token")
if not token:
return JSONResponse({"msg": "登录失败"}, status_code=401)
resp = JSONResponse({"msg": "ok"})
resp.set_cookie(
key="xbxs_token",
value=token,
max_age=60 * 60 * 24 * 7, # 7 天
httponly=False,
samesite="lax",
)
return resp