fix: 默认心跳先等够再报,新登录账号可以立刻开始
This commit is contained in:
@@ -94,7 +94,11 @@ def _persist(db: Session, employee_id: str, password: str, client: EunivClient,
|
||||
db.add(account)
|
||||
account.password_cipher = encrypt_secret(password)
|
||||
account.credential_cipher = encrypt_secret(_dump(client.export_credential()))
|
||||
account.credential_valid = True
|
||||
db.commit()
|
||||
from euniv.autostudy import sync_work
|
||||
|
||||
sync_work(employee_id)
|
||||
|
||||
|
||||
def _client(factory, employee_id: str, password: str, account: Account | None = None):
|
||||
@@ -464,18 +468,22 @@ def _refresh_one(employee_id: str, attempts: int, client_factory) -> None:
|
||||
continue
|
||||
raise
|
||||
except Exception as exc:
|
||||
import logging
|
||||
|
||||
from cryptography.fernet import InvalidToken
|
||||
|
||||
if isinstance(exc, InvalidToken):
|
||||
import logging
|
||||
|
||||
logging.getLogger("euniv.service").exception("账号 %s 的密文无法用当前密钥解开", employee_id)
|
||||
return
|
||||
logging.getLogger("euniv.service").exception("刷新账号 %s 的登录状态失败", employee_id)
|
||||
db.rollback()
|
||||
valid = False
|
||||
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
|
||||
finally:
|
||||
if client is not None:
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user