fix: 注销和删除会停掉学习,并去掉全员状态接口
This commit is contained in:
@@ -350,4 +350,7 @@ def delete_user(db: Session, employee_id: str) -> dict:
|
|||||||
account = _require(db, employee_id)
|
account = _require(db, employee_id)
|
||||||
db.delete(account)
|
db.delete(account)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
from euniv.autostudy import stop_account
|
||||||
|
|
||||||
|
stop_account(employee_id)
|
||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|||||||
@@ -395,13 +395,6 @@ def delete_proxy(request: Request, db: Session = Depends(get_db)) -> dict:
|
|||||||
return view_of(account)
|
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")
|
@app.get("/api/settings/study-control")
|
||||||
def get_study_control(request: Request, db: Session = Depends(get_db)) -> dict:
|
def get_study_control(request: Request, db: Session = Depends(get_db)) -> dict:
|
||||||
from euniv.autostudy import autostudy_status
|
from euniv.autostudy import autostudy_status
|
||||||
|
|||||||
@@ -256,6 +256,20 @@ def halt_work(employee_id: str) -> None:
|
|||||||
_notify(key, urgent=True)
|
_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:
|
def request_stop(employee_id: str) -> None:
|
||||||
key = (employee_id or "").strip()
|
key = (employee_id or "").strip()
|
||||||
if not key:
|
if not key:
|
||||||
|
|||||||
@@ -249,6 +249,10 @@ _SITE_SHARE_SECONDS = 90
|
|||||||
_site_sessions: dict[str, tuple[float, list[tuple[str, str, str, str]]]] = {}
|
_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:
|
def _remember_site(account_id: str, client: httpx.Client) -> None:
|
||||||
jar = getattr(getattr(client, "cookies", None), "jar", None)
|
jar = getattr(getattr(client, "cookies", None), "jar", None)
|
||||||
if not account_id or jar is None:
|
if not account_id or jar is None:
|
||||||
|
|||||||
@@ -345,11 +345,11 @@ def _live(db: Session, employee_id: str, client_factory, read):
|
|||||||
from euniv.proxy_pool import MAX_SWITCHES
|
from euniv.proxy_pool import MAX_SWITCHES
|
||||||
|
|
||||||
account = db.get(Account, employee_id)
|
account = db.get(Account, employee_id)
|
||||||
if account is None:
|
if account is None or not account.credential_cipher:
|
||||||
raise RuntimeError("请先登录")
|
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)
|
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
|
last_exc: BaseException | None = None
|
||||||
for _ in range(MAX_SWITCHES + 1):
|
for _ in range(MAX_SWITCHES + 1):
|
||||||
client = _client(client_factory, employee_id, password, account)
|
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:
|
if account is None:
|
||||||
return
|
return
|
||||||
account.credential_cipher = ""
|
account.credential_cipher = ""
|
||||||
|
account.password_cipher = ""
|
||||||
account.sessions_valid_after = datetime.now(timezone.utc)
|
account.sessions_valid_after = datetime.now(timezone.utc)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
from euniv.autostudy import stop_account
|
||||||
|
|
||||||
|
stop_account(employee_id)
|
||||||
|
|
||||||
|
|
||||||
def refresh_stored_credentials(client_factory=EunivClient) -> None:
|
def refresh_stored_credentials(client_factory=EunivClient) -> None:
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ def test_browser_session_logout_and_revoke() -> None:
|
|||||||
account = db.get(Account, "6650000146")
|
account = db.get(Account, "6650000146")
|
||||||
assert account is not None
|
assert account is not None
|
||||||
assert account.credential_cipher == ""
|
assert account.credential_cipher == ""
|
||||||
assert decrypt_secret(account.password_cipher) == "secret-pass"
|
assert account.password_cipher == ""
|
||||||
|
|
||||||
|
|
||||||
def test_logout_keeps_the_other_browser_until_revoke() -> None:
|
def test_logout_keeps_the_other_browser_until_revoke() -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user