fix: 注销和删除会停掉学习,并去掉全员状态接口

This commit is contained in:
2026-11-16 02:40:05 +08:00
parent 08e5a1b849
commit 42f2b457a0
6 changed files with 29 additions and 11 deletions
-7
View File
@@ -395,13 +395,6 @@ def delete_proxy(request: Request, db: Session = Depends(get_db)) -> dict:
return view_of(account)
@app.get("/api/autostudy/status")
def autostudy_state(request: Request, db: Session = Depends(get_db)) -> dict:
_signed_in(request, db)
from euniv.autostudy import autostudy_status
return autostudy_status()
@app.get("/api/settings/study-control")
def get_study_control(request: Request, db: Session = Depends(get_db)) -> dict:
from euniv.autostudy import autostudy_status
+14
View File
@@ -256,6 +256,20 @@ def halt_work(employee_id: str) -> None:
_notify(key, urgent=True)
def stop_account(employee_id: str) -> None:
"""停止学习、释放代理,并清掉内存里的状态和站点会话。"""
key = (employee_id or "").strip()
if not key:
return
request_stop(key)
from euniv.client import forget_site
from euniv.proxy_pool import release
release(key)
_clear_user_status(key)
forget_site(key)
def request_stop(employee_id: str) -> None:
key = (employee_id or "").strip()
if not key:
+4
View File
@@ -249,6 +249,10 @@ _SITE_SHARE_SECONDS = 90
_site_sessions: dict[str, tuple[float, list[tuple[str, str, str, str]]]] = {}
def forget_site(account_id: str) -> None:
_site_sessions.pop(account_id, None)
def _remember_site(account_id: str, client: httpx.Client) -> None:
jar = getattr(getattr(client, "cookies", None), "jar", None)
if not account_id or jar is None:
+7 -3
View File
@@ -345,11 +345,11 @@ def _live(db: Session, employee_id: str, client_factory, read):
from euniv.proxy_pool import MAX_SWITCHES
account = db.get(Account, employee_id)
if account is None:
if account is None or not account.credential_cipher:
raise RuntimeError("请先登录")
credential = json.loads(decrypt_secret(account.credential_cipher)) if account.credential_cipher else {}
credential = json.loads(decrypt_secret(account.credential_cipher))
attempts = _auto_attempts(db)
password = decrypt_secret(account.password_cipher)
password = decrypt_secret(account.password_cipher) if account.password_cipher else ""
last_exc: BaseException | None = None
for _ in range(MAX_SWITCHES + 1):
client = _client(client_factory, employee_id, password, account)
@@ -401,8 +401,12 @@ def revoke_credential(db: Session, employee_id: str) -> None:
if account is None:
return
account.credential_cipher = ""
account.password_cipher = ""
account.sessions_valid_after = datetime.now(timezone.utc)
db.commit()
from euniv.autostudy import stop_account
stop_account(employee_id)
def refresh_stored_credentials(client_factory=EunivClient) -> None: