feat: 登录后进入实时首页,并加密保存可刷新的登录凭证

This commit is contained in:
2026-10-26 18:12:00 +08:00
parent eaad01d5a8
commit 91707f959f
14 changed files with 748 additions and 136 deletions
+8 -5
View File
@@ -1,4 +1,4 @@
"""登录接口。本地只保存工号和加密密码。"""
"""登录接口。本地保存工号、加密密码和加密后的登录凭证。"""
from __future__ import annotations
@@ -11,7 +11,7 @@ from pydantic import BaseModel, Field
from sqlalchemy.orm import Session
from euniv.db import get_db, init_db
from euniv.service import list_accounts, login_and_store
from euniv.service import fetch_home, login_and_store
@asynccontextmanager
@@ -43,9 +43,12 @@ def login(body: LoginBody, db: Session = Depends(get_db)) -> dict:
return {"employee_id": employee_id}
@app.get("/api/accounts")
def accounts(db: Session = Depends(get_db)) -> list[dict]:
return [{"employee_id": item.employee_id} for item in list_accounts(db)]
@app.get("/api/home")
def home(employee_id: str, db: Session = Depends(get_db)) -> dict:
try:
return fetch_home(db, employee_id.strip())
except RuntimeError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
_dist = Path(__file__).resolve().parents[2] / "web" / "dist"