fix: 补上清单里还没对上的登录拒绝、会话回退和代理清理
This commit is contained in:
@@ -17,6 +17,7 @@ from euniv.client import (
|
||||
QR_PASSWORD_MARK,
|
||||
EunivClient,
|
||||
JigsawRejected,
|
||||
LoginRejected,
|
||||
ManualJigsaw,
|
||||
QrWaiting,
|
||||
SessionExpired,
|
||||
@@ -420,6 +421,14 @@ def _apply_hours_source(client, summary: dict, items: list | None = None) -> dic
|
||||
data["month_hours"] = totals["month"]
|
||||
data["today_hours"] = totals["today"]
|
||||
data["total_hours"] = totals["total"]
|
||||
data["limited"] = False
|
||||
walker = getattr(client, "month_history_minutes", None)
|
||||
if callable(walker):
|
||||
try:
|
||||
data["month_hours"] = walker()
|
||||
data["limited"] = bool(getattr(client, "history_limited", False))
|
||||
except Exception:
|
||||
data["limited"] = False
|
||||
return data
|
||||
|
||||
|
||||
@@ -439,13 +448,29 @@ def _api_hour_fields(client) -> dict:
|
||||
|
||||
|
||||
def _hour_fields(data: dict) -> dict:
|
||||
return {
|
||||
fields = {
|
||||
"hours_source": data.get("hours_source") or "api",
|
||||
"year_hours": data.get("year_hours"),
|
||||
"month_hours": data.get("month_hours"),
|
||||
"today_hours": data.get("today_hours"),
|
||||
"total_hours": data.get("total_hours"),
|
||||
}
|
||||
if data.get("limited") is True:
|
||||
fields["limited"] = True
|
||||
return fields
|
||||
|
||||
|
||||
def _drop_rejected_password(db: Session, employee_id: str) -> None:
|
||||
"""密码被平台拒绝后清掉登录凭证,停止自动重试。"""
|
||||
with _credential_lock(employee_id):
|
||||
db.rollback()
|
||||
account = db.get(Account, employee_id)
|
||||
if account is None:
|
||||
return
|
||||
account.credential_cipher = ""
|
||||
account.credential_valid = False
|
||||
account.last_refresh_at = datetime.now(timezone.utc)
|
||||
db.commit()
|
||||
|
||||
|
||||
def _auto_attempts(db: Session) -> int:
|
||||
@@ -496,6 +521,9 @@ def _live(db: Session, employee_id: str, client_factory, read):
|
||||
account.credential_cipher = encrypt_secret(_dump(updated))
|
||||
db.commit()
|
||||
return data
|
||||
except LoginRejected:
|
||||
_drop_rejected_password(db, employee_id)
|
||||
raise RuntimeError("请先登录") from None
|
||||
except RuntimeError:
|
||||
raise
|
||||
except Exception as exc:
|
||||
@@ -599,15 +627,16 @@ def _refresh_one(employee_id: str, attempts: int, client_factory) -> None:
|
||||
if isinstance(exc, InvalidToken):
|
||||
logging.getLogger("euniv.service").exception("账号 %s 的密文无法用当前密钥解开", employee_id)
|
||||
return
|
||||
if isinstance(exc, LoginRejected):
|
||||
logging.getLogger("euniv.service").warning("账号 %s 的密码已被拒绝,停止自动登录", employee_id)
|
||||
_drop_rejected_password(db, employee_id)
|
||||
return
|
||||
logging.getLogger("euniv.service").exception("刷新账号 %s 的登录状态失败", employee_id)
|
||||
db.rollback()
|
||||
account = db.get(Account, employee_id)
|
||||
if account is None:
|
||||
return
|
||||
rejected = isinstance(exc, RuntimeError) and any(
|
||||
word in str(exc) for word in ("登录失败", "登录页校验失败", "密码错误")
|
||||
)
|
||||
valid = False if rejected else account.credential_valid
|
||||
valid = account.credential_valid
|
||||
finally:
|
||||
if client is not None:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user