From 3670a76dfedefef9db11738a9088bd531f2ed0f5 Mon Sep 17 00:00:00 2001 From: Nixevol Date: Wed, 18 Nov 2026 10:16:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=80=80=E5=87=BA=E6=97=B6=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E7=A6=BB=E5=BC=80=E7=B3=BB=E7=BB=9F=E6=88=96=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=B4=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/euniv/service.py | 17 +++++----- backend/tests/test_api.py | 30 +++++++++++++---- web/src/shell/Shell.vue | 68 +++++++++++++++++++++++++-------------- web/src/styles.css | 13 ++++++++ 4 files changed, 88 insertions(+), 40 deletions(-) diff --git a/backend/euniv/service.py b/backend/euniv/service.py index 7238fdc..a27fc54 100644 --- a/backend/euniv/service.py +++ b/backend/euniv/service.py @@ -10,7 +10,7 @@ import time from datetime import datetime, timedelta, timezone from dataclasses import dataclass -from sqlalchemy import select +from sqlalchemy import delete, select from sqlalchemy.orm import Session from euniv.client import ( @@ -580,15 +580,16 @@ def _live(db: Session, employee_id: str, client_factory, read): def revoke_credential(db: Session, employee_id: str) -> None: + """从本平台删除账号,并停掉定时任务和已经开始的学习。""" + from euniv.models import FinishedCourse + with _credential_lock(employee_id): account = db.get(Account, employee_id) - if account is None: - return - db.refresh(account) - account.credential_cipher = "" - account.password_cipher = "" - account.sessions_valid_after = datetime.now(timezone.utc) - db.commit() + if account is not None: + db.refresh(account) + db.execute(delete(FinishedCourse).where(FinishedCourse.employee_id == employee_id)) + db.delete(account) + db.commit() from euniv.autostudy import stop_account from euniv.study_push import close_account diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 04b93d6..36f5b0a 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -352,16 +352,32 @@ def test_browser_session_logout_and_revoke(monkeypatch) -> None: account = db.get(Account, "6650000146") assert account is not None assert account.credential_cipher - again = client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}) - assert again.status_code == 200 - assert calls["login"] == 1 - assert client.post("/api/revoke").status_code == 200 - assert client.get("/api/session").status_code == 401 + account.study_schedule_enabled = True + db.commit() with SessionLocal() as db: account = db.get(Account, "6650000146") assert account is not None - assert account.credential_cipher == "" - assert account.password_cipher == "" + assert account.study_schedule_enabled is True + again = client.post("/api/login", json={"employee_id": "6650000146", "password": "secret-pass"}) + assert again.status_code == 200 + assert calls["login"] == 1 + from euniv.autostudy import _wanted + from euniv.models import FinishedCourse + + _wanted["6650000146"] = object() + with SessionLocal() as db: + db.add(FinishedCourse(employee_id="6650000146", knowledge_id="course-1")) + db.commit() + assert client.post("/api/revoke").status_code == 200 + assert client.get("/api/session").status_code == 401 + assert "6650000146" not in _wanted + with SessionLocal() as db: + from sqlalchemy import select + + account = db.get(Account, "6650000146") + assert account is None + left = db.scalars(select(FinishedCourse).where(FinishedCourse.employee_id == "6650000146")).all() + assert left == [] def test_logout_keeps_the_other_browser_until_revoke(monkeypatch) -> None: diff --git a/web/src/shell/Shell.vue b/web/src/shell/Shell.vue index c8e73bd..05093c9 100644 --- a/web/src/shell/Shell.vue +++ b/web/src/shell/Shell.vue @@ -1,6 +1,6 @@ @@ -139,11 +133,9 @@ function onLogout(key: string) { {{ isDark ? "切换到日间" : "切换到夜间" }} - - - - - + + + @@ -153,5 +145,31 @@ function onLogout(key: string) { + + + 退出系统 + 注销账号 + +

定时计划和已开始的任务不会受影响。

+

会从平台删除这个账号,定时任务和已开始的任务会一并删除。

+ +
diff --git a/web/src/styles.css b/web/src/styles.css index d87c4c0..b5fbf22 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -1644,6 +1644,19 @@ select { gap: 8px; } +.leave-choices { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 12px; +} + +.leave-note { + margin: 16px 0 0; + color: var(--ink); + line-height: 1.6; +} + .app-root { position: relative; }