feat: 对接 UAC 登录并支持 iCenter 扫码
This commit is contained in:
@@ -26,8 +26,10 @@ from euniv.service import (
|
||||
fetch_study_history,
|
||||
fetch_training_detail,
|
||||
login_and_store,
|
||||
poll_qr_login,
|
||||
revoke_credential,
|
||||
start_credential_refresh,
|
||||
start_qr_login,
|
||||
submit_jigsaw,
|
||||
)
|
||||
from euniv.session import clear_session, read_employee_id, write_session
|
||||
@@ -102,6 +104,10 @@ class JigsawBody(BaseModel):
|
||||
offset: int = Field(ge=0, le=2000)
|
||||
|
||||
|
||||
class QrPollBody(BaseModel):
|
||||
attempt_id: str = Field(min_length=8, max_length=64)
|
||||
|
||||
|
||||
@app.get("/api/health")
|
||||
def health() -> dict:
|
||||
return {"ok": True}
|
||||
@@ -162,6 +168,25 @@ def login_jigsaw(body: JigsawBody, response: Response, db: Session = Depends(get
|
||||
return _open_session(response, payload)
|
||||
|
||||
|
||||
@app.post("/api/login/qr")
|
||||
def login_qr() -> dict:
|
||||
try:
|
||||
return start_qr_login()
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
|
||||
|
||||
@app.post("/api/login/qr/poll")
|
||||
def login_qr_poll(body: QrPollBody, response: Response, db: Session = Depends(get_db)) -> dict:
|
||||
try:
|
||||
payload = poll_qr_login(db, body.attempt_id)
|
||||
except RuntimeError as exc:
|
||||
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
||||
if payload.get("employee_id"):
|
||||
return _open_session(response, payload)
|
||||
return payload
|
||||
|
||||
|
||||
@app.post("/api/logout")
|
||||
def logout(response: Response) -> dict:
|
||||
clear_session(response)
|
||||
|
||||
Reference in New Issue
Block a user