fix: 清掉无用接口和样式,并收紧登录与工号边界

This commit is contained in:
2026-11-16 11:30:59 +08:00
parent 7381b49e4c
commit 5b83b7e415
15 changed files with 232 additions and 329 deletions
+6 -6
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException, Request, Response
from fastapi import APIRouter, Depends, HTTPException, Path, Query, Request, Response
from pydantic import BaseModel
from sqlalchemy.orm import Session
@@ -130,8 +130,8 @@ def post_courses_load(_: str = Depends(require_admin)) -> dict:
def get_courses(
q: str = "",
kind: str = "",
offset: int = 0,
limit: int = 50,
offset: int = Query(default=0, ge=0, le=10**9),
limit: int = Query(default=50, ge=1, le=10**9),
db: Session = Depends(get_db),
_: str = Depends(require_admin),
) -> dict:
@@ -144,8 +144,8 @@ def get_courses(
def get_proxies(
q: str = "",
status: str = "",
offset: int = 0,
limit: int = 50,
offset: int = Query(default=0, ge=0, le=10**9),
limit: int = Query(default=50, ge=1, le=10**9),
db: Session = Depends(get_db),
_: str = Depends(require_admin),
) -> dict:
@@ -168,7 +168,7 @@ def get_proxies_probe(_: str = Depends(require_admin)) -> dict:
@admin_router.post("/proxies/{proxy_id}/probe")
def post_proxy_probe(proxy_id: int, _: str = Depends(require_admin)) -> dict:
def post_proxy_probe(proxy_id: int = Path(ge=1, le=10**9), _: str = Depends(require_admin)) -> dict:
try:
return probe_proxy_one(proxy_id)
except ProxyProbeError as exc:
+3 -70
View File
@@ -14,14 +14,12 @@ from euniv.models import Account
from euniv.course_workers import CourseWorkersError
from euniv.course_workers import apply as apply_workers
from euniv.course_workers import of as workers_of
from euniv.course_workers import view_of as workers_view
from euniv.proxy import ProxyError, apply, clear, enabled, summary_of, url_of, view_of
from euniv.study_control import start_now, stop_now
from euniv.study_control import view_of as study_view
from euniv.study_window import StudyWindowError
from euniv.study_window import apply as apply_start
from euniv.study_window import label_of as start_label
from euniv.study_window import view_of as start_view
_TOKEN_KEYS = (
"ucs_token",
@@ -119,8 +117,6 @@ def check_employee(db: Session, employee_id: str) -> dict:
account = _require(db, employee_id)
if not account.credential_cipher:
return {"employee_id": employee_id, "result": "未保存"}
before_password = account.password_cipher
before_credential = account.credential_cipher
password = decrypt_secret(account.password_cipher) if account.password_cipher else ""
credential = json.loads(decrypt_secret(account.credential_cipher))
pooled = uses_pool(account)
@@ -158,9 +154,6 @@ def check_employee(db: Session, employee_id: str) -> dict:
pass
if account is None:
raise HTTPException(status_code=404, detail="用户不存在")
if result != "检查失败":
account.password_cipher = before_password
account.credential_cipher = before_credential
record_outcome(account, valid)
db.commit()
payload = {"employee_id": employee_id, "result": result}
@@ -240,30 +233,6 @@ def read_proxy(db: Session, employee_id: str) -> dict:
return view_of(_require(db, employee_id))
def set_proxy(
db: Session,
employee_ids: list[str],
scheme: str,
host: str = "",
port: object = None,
username: str = "",
password: str | None = None,
) -> dict:
accounts = _accounts_by_ids(db, employee_ids)
try:
for account in accounts:
apply(account, scheme, host, port, username, password)
except ProxyError as exc:
db.rollback()
raise HTTPException(status_code=400, detail=str(exc)) from exc
db.commit()
from euniv.autostudy import restart_work
for account in accounts:
restart_work(account.employee_id)
return {"ok": True, "count": len(accounts)}
def clear_proxy(db: Session, employee_ids: list[str]) -> dict:
accounts = _accounts_by_ids(db, employee_ids)
for account in accounts:
@@ -276,45 +245,6 @@ def clear_proxy(db: Session, employee_ids: list[str]) -> dict:
return {"ok": True, "count": len(accounts)}
def read_study_start(db: Session, employee_id: str) -> dict:
return start_view(_require(db, employee_id))
def set_study_start(
db: Session,
employee_ids: list[str],
day: int,
hour: int,
minute: int,
second: int,
) -> dict:
accounts = _accounts_by_ids(db, employee_ids)
try:
for account in accounts:
apply_start(account, day, hour, minute, second)
except StudyWindowError as exc:
db.rollback()
raise HTTPException(status_code=400, detail=str(exc)) from exc
db.commit()
return {"ok": True, "count": len(accounts)}
def read_course_workers(db: Session, employee_id: str) -> dict:
return workers_view(_require(db, employee_id))
def set_course_workers(db: Session, employee_ids: list[str], workers: int) -> dict:
accounts = _accounts_by_ids(db, employee_ids)
try:
for account in accounts:
apply_workers(account, workers)
except CourseWorkersError as exc:
db.rollback()
raise HTTPException(status_code=400, detail=str(exc)) from exc
db.commit()
return {"ok": True, "count": len(accounts)}
def set_study_action(db: Session, employee_ids: list[str], action: str) -> dict:
kind = (action or "").strip().lower()
if kind not in {"start", "stop"}:
@@ -391,4 +321,7 @@ def delete_user(db: Session, employee_id: str) -> dict:
from euniv.autostudy import stop_account
stop_account(employee_id)
from euniv.service import release_credential_lock
release_credential_lock(employee_id)
return {"ok": True}