fix: 扫码不再覆盖已有密码,登录按地址限速
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
"""记录最近一次真实密码登录的时间。"""
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
revision = "0005_password_login_at"
|
||||||
|
down_revision = "0004_finished_courses"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.add_column(
|
||||||
|
"accounts",
|
||||||
|
sa.Column(
|
||||||
|
"password_login_at",
|
||||||
|
sa.DateTime(timezone=True),
|
||||||
|
server_default=sa.text("CURRENT_TIMESTAMP"),
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.drop_column("accounts", "password_login_at")
|
||||||
+18
-2
@@ -19,6 +19,7 @@ from admin.session import admin_session_active, clear_admin_session, write_admin
|
|||||||
from admin.settings import ensure_admin_seed, jigsaw_plan, load_admin_identity, load_config
|
from admin.settings import ensure_admin_seed, jigsaw_plan, load_admin_identity, load_config
|
||||||
from euniv.db import get_db, init_db
|
from euniv.db import get_db, init_db
|
||||||
from euniv.models import Account
|
from euniv.models import Account
|
||||||
|
from euniv.login_limit import allow as login_allowed
|
||||||
from euniv.service import (
|
from euniv.service import (
|
||||||
fetch_exam_detail,
|
fetch_exam_detail,
|
||||||
fetch_home,
|
fetch_home,
|
||||||
@@ -32,6 +33,7 @@ from euniv.service import (
|
|||||||
revoke_credential,
|
revoke_credential,
|
||||||
start_credential_refresh,
|
start_credential_refresh,
|
||||||
start_qr_login,
|
start_qr_login,
|
||||||
|
start_pending_cleaner,
|
||||||
submit_jigsaw,
|
submit_jigsaw,
|
||||||
)
|
)
|
||||||
from euniv.session import clear_session, write_session
|
from euniv.session import clear_session, write_session
|
||||||
@@ -88,6 +90,7 @@ async def lifespan(_app: FastAPI):
|
|||||||
|
|
||||||
study_worker = start_autostudy()
|
study_worker = start_autostudy()
|
||||||
stop_pool = start_proxy_pool()
|
stop_pool = start_proxy_pool()
|
||||||
|
start_pending_cleaner()
|
||||||
yield
|
yield
|
||||||
if study_worker is not None:
|
if study_worker is not None:
|
||||||
study_worker.stop()
|
study_worker.stop()
|
||||||
@@ -97,7 +100,14 @@ async def lifespan(_app: FastAPI):
|
|||||||
stop_refresh.set()
|
stop_refresh.set()
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI(title="EunivTools", lifespan=lifespan)
|
_openapi = os.environ.get("EUNIV_OPENAPI") == "1"
|
||||||
|
app = FastAPI(
|
||||||
|
title="EunivTools",
|
||||||
|
lifespan=lifespan,
|
||||||
|
docs_url="/docs" if _openapi else None,
|
||||||
|
redoc_url="/redoc" if _openapi else None,
|
||||||
|
openapi_url="/openapi.json" if _openapi else None,
|
||||||
|
)
|
||||||
app.include_router(public_router)
|
app.include_router(public_router)
|
||||||
app.include_router(admin_router)
|
app.include_router(admin_router)
|
||||||
|
|
||||||
@@ -169,6 +179,10 @@ def _client_host(request: Request) -> str:
|
|||||||
@app.post("/api/login")
|
@app.post("/api/login")
|
||||||
def login(body: LoginBody, request: Request, response: Response, db: Session = Depends(get_db)) -> dict:
|
def login(body: LoginBody, request: Request, response: Response, db: Session = Depends(get_db)) -> dict:
|
||||||
account = body.employee_id.strip()
|
account = body.employee_id.strip()
|
||||||
|
if not account:
|
||||||
|
raise HTTPException(status_code=400, detail="请填写工号")
|
||||||
|
if not login_allowed(_client_host(request)):
|
||||||
|
raise HTTPException(status_code=429, detail="登录过于频繁,请稍后再试")
|
||||||
if identity.matches(account):
|
if identity.matches(account):
|
||||||
source = _client_host(request)
|
source = _client_host(request)
|
||||||
if too_many(source):
|
if too_many(source):
|
||||||
@@ -200,7 +214,9 @@ def login_jigsaw(body: JigsawBody, response: Response, db: Session = Depends(get
|
|||||||
|
|
||||||
|
|
||||||
@app.post("/api/login/qr")
|
@app.post("/api/login/qr")
|
||||||
def login_qr() -> dict:
|
def login_qr(request: Request) -> dict:
|
||||||
|
if not login_allowed(_client_host(request)):
|
||||||
|
raise HTTPException(status_code=429, detail="登录过于频繁,请稍后再试")
|
||||||
try:
|
try:
|
||||||
return start_qr_login()
|
return start_qr_login()
|
||||||
except RuntimeError as exc:
|
except RuntimeError as exc:
|
||||||
|
|||||||
+36
-16
@@ -8,6 +8,7 @@ import io
|
|||||||
import json
|
import json
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import secrets
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
@@ -188,7 +189,7 @@ def make_qr_payload(prefix: str = QR_PREFIX) -> str:
|
|||||||
return hashlib.md5(text.encode("utf-8")).hexdigest()
|
return hashlib.md5(text.encode("utf-8")).hexdigest()
|
||||||
|
|
||||||
def digits(count: int) -> str:
|
def digits(count: int) -> str:
|
||||||
return "".join(random.choice("0123456789") for _ in range(count))
|
return "".join(secrets.choice("0123456789") for _ in range(count))
|
||||||
|
|
||||||
key = digest(prefix + str(now_ms()) + digits(10))
|
key = digest(prefix + str(now_ms()) + digits(10))
|
||||||
value = digest(key + digits(10))
|
value = digest(key + digits(10))
|
||||||
@@ -247,21 +248,28 @@ def _authorize_lock(account_id: str) -> threading.Lock:
|
|||||||
|
|
||||||
|
|
||||||
_SITE_SHARE_SECONDS = 90
|
_SITE_SHARE_SECONDS = 90
|
||||||
_site_sessions: dict[str, tuple[float, list[tuple[str, str, str, str]]]] = {}
|
_site_sessions: dict[tuple[str, str], tuple[float, list[tuple[str, str, str, str]]]] = {}
|
||||||
|
|
||||||
|
|
||||||
def forget_site(account_id: str) -> None:
|
def forget_site(account_id: str) -> None:
|
||||||
_site_sessions.pop(account_id, None)
|
key = (account_id or "").strip()
|
||||||
|
for item in list(_site_sessions):
|
||||||
|
if item[0] == key:
|
||||||
|
_site_sessions.pop(item, None)
|
||||||
|
|
||||||
|
|
||||||
def _remember_site(account_id: str, client: httpx.Client) -> None:
|
def _remember_site(account_id: str, client: httpx.Client, token: str = "") -> 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:
|
||||||
return
|
return
|
||||||
|
now = time.time()
|
||||||
|
for item, (saved, _rows) in list(_site_sessions.items()):
|
||||||
|
if now - saved > _SITE_SHARE_SECONDS:
|
||||||
|
_site_sessions.pop(item, None)
|
||||||
dumped = []
|
dumped = []
|
||||||
for cookie in jar:
|
for cookie in jar:
|
||||||
dumped.append((cookie.name, cookie.value or "", cookie.domain or "", cookie.path or "/"))
|
dumped.append((cookie.name, cookie.value or "", cookie.domain or "", cookie.path or "/"))
|
||||||
_site_sessions[account_id] = (time.time(), dumped)
|
_site_sessions[(account_id, token)] = (now, dumped)
|
||||||
|
|
||||||
|
|
||||||
def _load_cookies(client: httpx.Client | httpx.AsyncClient, dumped: list[tuple[str, str, str, str]]) -> None:
|
def _load_cookies(client: httpx.Client | httpx.AsyncClient, dumped: list[tuple[str, str, str, str]]) -> None:
|
||||||
@@ -845,16 +853,25 @@ class EunivClient:
|
|||||||
parts = self._qr_str.split(":")
|
parts = self._qr_str.split(":")
|
||||||
if len(parts) < 3:
|
if len(parts) < 3:
|
||||||
raise RuntimeError("请重新扫码")
|
raise RuntimeError("请重新扫码")
|
||||||
payload = self._uac_post(
|
try:
|
||||||
"/authentication/qrscan.serv",
|
payload = self._uac_post(
|
||||||
json_body={"qrCodeKey": parts[1], "qrCodeValue": parts[2]},
|
"/authentication/qrscan.serv",
|
||||||
).json()
|
json_body={"qrCodeKey": parts[1], "qrCodeValue": parts[2]},
|
||||||
|
).json()
|
||||||
|
except (httpx.TransportError, TimeoutError):
|
||||||
|
self._qr_misses = getattr(self, "_qr_misses", 0) + 1
|
||||||
|
if self._qr_misses >= 5:
|
||||||
|
raise RuntimeError("扫码状态没有获取到") from None
|
||||||
|
raise QrWaiting() from None
|
||||||
top, inner, data, message = parse_uac(payload)
|
top, inner, data, message = parse_uac(payload)
|
||||||
if top == UAC_OK and inner == UAC_QR_WAIT:
|
if top == UAC_OK and inner == UAC_QR_WAIT:
|
||||||
raise QrWaiting()
|
raise QrWaiting()
|
||||||
if top == UAC_OK and inner == UAC_OK and isinstance(data, dict) and data.get("token"):
|
if top == UAC_OK and inner == UAC_OK and isinstance(data, dict) and data.get("token"):
|
||||||
self.login_name = str(data.get("accountId") or data.get("userName") or self.login_name)
|
self.login_name = str(data.get("accountId") or data.get("userName") or self.login_name)
|
||||||
|
self._qr_misses = 0
|
||||||
return data
|
return data
|
||||||
|
if any(word in (message or "") for word in ("已扫码", "待确认", "确认中")):
|
||||||
|
raise QrWaiting()
|
||||||
raise RuntimeError(message or "扫码登录失败")
|
raise RuntimeError(message or "扫码登录失败")
|
||||||
|
|
||||||
def _login_with_jigsaw(self, manual: bool, auto_attempts: int) -> dict:
|
def _login_with_jigsaw(self, manual: bool, auto_attempts: int) -> dict:
|
||||||
@@ -1175,6 +1192,8 @@ class EunivClient:
|
|||||||
"""读取「我的学时」列表:来源、获得学时(分钟)、日期。"""
|
"""读取「我的学时」列表:来源、获得学时(分钟)、日期。"""
|
||||||
try:
|
try:
|
||||||
items = self._study_history_search(pageable=False)
|
items = self._study_history_search(pageable=False)
|
||||||
|
except SessionExpired:
|
||||||
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
items = None
|
items = None
|
||||||
if items is not None:
|
if items is not None:
|
||||||
@@ -1193,10 +1212,10 @@ class EunivClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
return accumulate_month_minutes(fetch_page, year, month)
|
return accumulate_month_minutes(fetch_page, year, month)
|
||||||
except Exception:
|
except SessionExpired:
|
||||||
items = self.study_history()
|
raise
|
||||||
total, _ = fold_month_minutes(items, year, month)
|
except Exception as exc:
|
||||||
return total
|
raise RuntimeError("学时历史没有获取到") from exc
|
||||||
|
|
||||||
def _study_history_search(
|
def _study_history_search(
|
||||||
self, *, pageable: bool, offset: int = 0, limit: int = HISTORY_PAGE_SIZE
|
self, *, pageable: bool, offset: int = 0, limit: int = HISTORY_PAGE_SIZE
|
||||||
@@ -1243,7 +1262,8 @@ class EunivClient:
|
|||||||
with _authorize_lock(account_id):
|
with _authorize_lock(account_id):
|
||||||
if getattr(self, "_site_ready", False):
|
if getattr(self, "_site_ready", False):
|
||||||
return ""
|
return ""
|
||||||
shared = _site_sessions.get(account_id)
|
token = str(self._profile.get("token") or "")
|
||||||
|
shared = _site_sessions.get((account_id, token))
|
||||||
if shared and time.time() - shared[0] < _SITE_SHARE_SECONDS:
|
if shared and time.time() - shared[0] < _SITE_SHARE_SECONDS:
|
||||||
_load_cookies(self.client, shared[1])
|
_load_cookies(self.client, shared[1])
|
||||||
self._site_ready = True
|
self._site_ready = True
|
||||||
@@ -1255,10 +1275,10 @@ class EunivClient:
|
|||||||
if "spMonthlyPeriod" not in probe.text:
|
if "spMonthlyPeriod" not in probe.text:
|
||||||
self.authorize(self._profile)
|
self.authorize(self._profile)
|
||||||
self._site_ready = True
|
self._site_ready = True
|
||||||
_remember_site(account_id, self.client)
|
_remember_site(account_id, self.client, token)
|
||||||
return ""
|
return ""
|
||||||
self._site_ready = True
|
self._site_ready = True
|
||||||
_remember_site(account_id, self.client)
|
_remember_site(account_id, self.client, token)
|
||||||
return probe.text
|
return probe.text
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
"""未登录接口按来源地址限速。状态只放内存。"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
_hits: dict[str, list[float]] = {}
|
||||||
|
_WINDOW = 60.0
|
||||||
|
_LIMIT = 30
|
||||||
|
|
||||||
|
|
||||||
|
def reset() -> None:
|
||||||
|
_hits.clear()
|
||||||
|
|
||||||
|
|
||||||
|
def allow(source: str, limit: int = _LIMIT, window: float = _WINDOW) -> bool:
|
||||||
|
now = time.monotonic()
|
||||||
|
key = (source or "unknown").strip() or "unknown"
|
||||||
|
recent = [item for item in _hits.get(key, []) if now - item < window]
|
||||||
|
if len(recent) >= limit:
|
||||||
|
_hits[key] = recent
|
||||||
|
return False
|
||||||
|
recent.append(now)
|
||||||
|
_hits[key] = recent
|
||||||
|
return True
|
||||||
@@ -77,6 +77,9 @@ class Account(Base):
|
|||||||
sessions_valid_after: Mapped[datetime] = mapped_column(
|
sessions_valid_after: Mapped[datetime] = mapped_column(
|
||||||
DateTime(timezone=True), nullable=False, server_default=text("CURRENT_TIMESTAMP")
|
DateTime(timezone=True), nullable=False, server_default=text("CURRENT_TIMESTAMP")
|
||||||
)
|
)
|
||||||
|
password_login_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime(timezone=True), nullable=False, server_default=text("CURRENT_TIMESTAMP")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ProxyNode(Base):
|
class ProxyNode(Base):
|
||||||
|
|||||||
+80
-13
@@ -7,7 +7,7 @@ import json
|
|||||||
import secrets
|
import secrets
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@@ -49,6 +49,7 @@ class PendingLogin:
|
|||||||
employee_id: str
|
employee_id: str
|
||||||
password: str
|
password: str
|
||||||
created: float
|
created: float
|
||||||
|
tries: int = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -61,6 +62,22 @@ def _dump(credential: dict) -> str:
|
|||||||
return json.dumps(credential, ensure_ascii=False, sort_keys=True)
|
return json.dumps(credential, ensure_ascii=False, sort_keys=True)
|
||||||
|
|
||||||
|
|
||||||
|
def start_pending_cleaner() -> None:
|
||||||
|
"""定时丢掉过期的登录会话,不依赖下一次请求。"""
|
||||||
|
|
||||||
|
def loop() -> None:
|
||||||
|
while True:
|
||||||
|
time.sleep(30)
|
||||||
|
try:
|
||||||
|
_purge_pending()
|
||||||
|
except Exception:
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logging.getLogger("euniv.service").exception("清理未完成的登录失败")
|
||||||
|
|
||||||
|
threading.Thread(target=loop, name="euniv-pending", daemon=True).start()
|
||||||
|
|
||||||
|
|
||||||
def _purge_pending() -> None:
|
def _purge_pending() -> None:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
for attempt_id, pending in list(_pending.items()):
|
for attempt_id, pending in list(_pending.items()):
|
||||||
@@ -86,16 +103,45 @@ def _drop_employee(employee_id: str) -> None:
|
|||||||
_pending.pop(attempt_id, None)
|
_pending.pop(attempt_id, None)
|
||||||
|
|
||||||
|
|
||||||
def _persist(db: Session, employee_id: str, password: str, client: EunivClient, profile: dict) -> None:
|
def _persist(db: Session, employee_id: str, password: str | None, client: EunivClient, profile: dict) -> None:
|
||||||
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
client.authorize(profile)
|
client.authorize(profile)
|
||||||
account = db.get(Account, employee_id)
|
account = db.get(Account, employee_id)
|
||||||
if account is None:
|
if account is None:
|
||||||
account = Account(employee_id=employee_id, password_cipher="", credential_cipher="")
|
account = Account(employee_id=employee_id, password_cipher="", credential_cipher="")
|
||||||
db.add(account)
|
db.add(account)
|
||||||
account.password_cipher = encrypt_secret(password)
|
if password is None:
|
||||||
|
stored = ""
|
||||||
|
if account.password_cipher:
|
||||||
|
try:
|
||||||
|
stored = decrypt_secret(account.password_cipher)
|
||||||
|
except Exception:
|
||||||
|
stored = ""
|
||||||
|
if not stored or is_qr_password(stored):
|
||||||
|
account.password_cipher = encrypt_secret(QR_PASSWORD_MARK)
|
||||||
|
else:
|
||||||
|
account.password_cipher = encrypt_secret(password)
|
||||||
|
account.password_login_at = datetime.now(timezone.utc)
|
||||||
account.credential_cipher = encrypt_secret(_dump(client.export_credential()))
|
account.credential_cipher = encrypt_secret(_dump(client.export_credential()))
|
||||||
account.credential_valid = True
|
account.credential_valid = True
|
||||||
db.commit()
|
try:
|
||||||
|
db.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
db.rollback()
|
||||||
|
account = db.get(Account, employee_id)
|
||||||
|
if account is None:
|
||||||
|
raise
|
||||||
|
if password is None:
|
||||||
|
stored = decrypt_secret(account.password_cipher) if account.password_cipher else ""
|
||||||
|
if not stored or is_qr_password(stored):
|
||||||
|
account.password_cipher = encrypt_secret(QR_PASSWORD_MARK)
|
||||||
|
else:
|
||||||
|
account.password_cipher = encrypt_secret(password)
|
||||||
|
account.password_login_at = datetime.now(timezone.utc)
|
||||||
|
account.credential_cipher = encrypt_secret(_dump(client.export_credential()))
|
||||||
|
account.credential_valid = True
|
||||||
|
db.commit()
|
||||||
from euniv.autostudy import sync_work
|
from euniv.autostudy import sync_work
|
||||||
|
|
||||||
sync_work(employee_id)
|
sync_work(employee_id)
|
||||||
@@ -124,6 +170,19 @@ def _switch_proxy(account: Account | None, client, exc: BaseException) -> bool:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def fresh_password(account: Account) -> bool:
|
||||||
|
confirmed = getattr(account, "password_login_at", None)
|
||||||
|
if confirmed is None:
|
||||||
|
return False
|
||||||
|
if confirmed.tzinfo is None:
|
||||||
|
confirmed = confirmed.replace(tzinfo=timezone.utc)
|
||||||
|
return datetime.now(timezone.utc) - confirmed <= timedelta(days=7)
|
||||||
|
|
||||||
|
|
||||||
|
def _resolved_id(profile: dict, fallback: str) -> str:
|
||||||
|
return str(profile.get("accountId") or fallback or "").strip() or fallback
|
||||||
|
|
||||||
|
|
||||||
def login_and_store(
|
def login_and_store(
|
||||||
db: Session,
|
db: Session,
|
||||||
employee_id: str,
|
employee_id: str,
|
||||||
@@ -142,10 +201,9 @@ def login_and_store(
|
|||||||
not is_qr_password(stored)
|
not is_qr_password(stored)
|
||||||
and hmac.compare_digest(stored.encode("utf-8"), password.encode("utf-8"))
|
and hmac.compare_digest(stored.encode("utf-8"), password.encode("utf-8"))
|
||||||
)
|
)
|
||||||
if same_password and _credential_still_valid(account, client_factory):
|
if same_password and fresh_password(account) and _credential_still_valid(account, client_factory):
|
||||||
_request_course_sync(employee_id)
|
_request_course_sync(employee_id)
|
||||||
return {"employee_id": employee_id}
|
return {"employee_id": employee_id}
|
||||||
_drop_employee(employee_id)
|
|
||||||
from euniv.proxy_pool import MAX_SWITCHES
|
from euniv.proxy_pool import MAX_SWITCHES
|
||||||
|
|
||||||
held = False
|
held = False
|
||||||
@@ -168,9 +226,12 @@ def login_and_store(
|
|||||||
client = None
|
client = None
|
||||||
continue
|
continue
|
||||||
raise
|
raise
|
||||||
_persist(db, employee_id, password, client, profile)
|
resolved = _resolved_id(profile, employee_id)
|
||||||
_request_course_sync(employee_id)
|
_persist(db, resolved, password, client, profile)
|
||||||
return {"employee_id": employee_id}
|
_drop_employee(employee_id)
|
||||||
|
_drop_employee(resolved)
|
||||||
|
_request_course_sync(resolved)
|
||||||
|
return {"employee_id": resolved}
|
||||||
if last_exc is not None:
|
if last_exc is not None:
|
||||||
raise last_exc
|
raise last_exc
|
||||||
raise RuntimeError("登录失败")
|
raise RuntimeError("登录失败")
|
||||||
@@ -205,6 +266,11 @@ def submit_jigsaw(db: Session, attempt_id: str, offset: int) -> dict:
|
|||||||
try:
|
try:
|
||||||
profile = pending.client.submit_jigsaw(offset)
|
profile = pending.client.submit_jigsaw(offset)
|
||||||
except JigsawRejected:
|
except JigsawRejected:
|
||||||
|
pending.tries += 1
|
||||||
|
if pending.tries >= 5:
|
||||||
|
_pending.pop(attempt_id, None)
|
||||||
|
pending.client.close()
|
||||||
|
raise RuntimeError("请重新登录")
|
||||||
pending.created = time.time()
|
pending.created = time.time()
|
||||||
return {"attempt_id": attempt_id, "jigsaw": pending.client.next_jigsaw()}
|
return {"attempt_id": attempt_id, "jigsaw": pending.client.next_jigsaw()}
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -213,9 +279,10 @@ def submit_jigsaw(db: Session, attempt_id: str, offset: int) -> dict:
|
|||||||
raise
|
raise
|
||||||
_pending.pop(attempt_id, None)
|
_pending.pop(attempt_id, None)
|
||||||
try:
|
try:
|
||||||
_persist(db, pending.employee_id, pending.password, pending.client, profile)
|
resolved = _resolved_id(profile, pending.employee_id)
|
||||||
_request_course_sync(pending.employee_id)
|
_persist(db, resolved, pending.password, pending.client, profile)
|
||||||
return {"employee_id": pending.employee_id}
|
_request_course_sync(resolved)
|
||||||
|
return {"employee_id": resolved}
|
||||||
finally:
|
finally:
|
||||||
pending.client.close()
|
pending.client.close()
|
||||||
|
|
||||||
@@ -253,7 +320,7 @@ def poll_qr_login(db: Session, attempt_id: str, client_factory=EunivClient) -> d
|
|||||||
pending.client.close()
|
pending.client.close()
|
||||||
raise RuntimeError("扫码登录没有返回工号")
|
raise RuntimeError("扫码登录没有返回工号")
|
||||||
try:
|
try:
|
||||||
_persist(db, employee_id, QR_PASSWORD_MARK, pending.client, profile)
|
_persist(db, employee_id, None, pending.client, profile)
|
||||||
_request_course_sync(employee_id)
|
_request_course_sync(employee_id)
|
||||||
return {"employee_id": employee_id}
|
return {"employee_id": employee_id}
|
||||||
finally:
|
finally:
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ def fresh_database():
|
|||||||
from admin.login_limit import reset
|
from admin.login_limit import reset
|
||||||
|
|
||||||
reset()
|
reset()
|
||||||
|
from euniv.login_limit import reset as reset_login
|
||||||
|
|
||||||
|
reset_login()
|
||||||
from euniv.proxy_pool import _holds
|
from euniv.proxy_pool import _holds
|
||||||
|
|
||||||
_holds.clear()
|
_holds.clear()
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ def test_login_stores_password_and_credential_only() -> None:
|
|||||||
"study_ignore_window",
|
"study_ignore_window",
|
||||||
"study_schedule_enabled",
|
"study_schedule_enabled",
|
||||||
"sessions_valid_after",
|
"sessions_valid_after",
|
||||||
|
"password_login_at",
|
||||||
}
|
}
|
||||||
|
|
||||||
home = client.get("/api/home")
|
home = client.get("/api/home")
|
||||||
|
|||||||
Reference in New Issue
Block a user