fix: change datetime.now() to datetime.datetime.now() in up_login.dspy

ahserver pre-loads 'import datetime' module, so datetime class must be
accessed as datetime.datetime, not directly as datetime (which was only
valid when 'from datetime import datetime' was used).
This commit is contained in:
yumoqing 2026-04-26 11:37:30 +08:00
parent 1b5ae8aba9
commit c0c9d0a489

View File

@ -27,8 +27,8 @@ async with db.sqlorContext(dbname) as sor:
last_fail = getattr(user, 'last_login_fail', None) last_fail = getattr(user, 'last_login_fail', None)
if fail_count >= 3 and last_fail: if fail_count >= 3 and last_fail:
try: try:
stored = datetime.strptime(str(last_fail), '%Y-%m-%d %H:%M:%S') stored = datetime.datetime.strptime(str(last_fail), '%Y-%m-%d %H:%M:%S')
elapsed = (datetime.now() - stored).total_seconds() elapsed = (datetime.datetime.now() - stored).total_seconds()
if elapsed < 300: if elapsed < 300:
return { return {
"widgettype":"Error", "widgettype":"Error",
@ -51,7 +51,7 @@ async with db.sqlorContext(dbname) as sor:
r = await sor.sqlExe('select * from users where username=${username}$ and password=${password}$', ns.copy()) r = await sor.sqlExe('select * from users where username=${username}$ and password=${password}$', ns.copy())
if len(r) == 0: if len(r) == 0:
# Atomic increment -- standard SQL # Atomic increment -- standard SQL
now_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S') now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
await sor.sqlExe(""" await sor.sqlExe("""
UPDATE users UPDATE users
SET login_fail_count = login_fail_count + 1, SET login_fail_count = login_fail_count + 1,
@ -73,7 +73,7 @@ async with db.sqlorContext(dbname) as sor:
} }
} }
# Success -- atomic reset # Success -- atomic reset
now_str = datetime.now().strftime('%Y-%m-%d %H:%M:%S') now_str = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
await sor.sqlExe(""" await sor.sqlExe("""
UPDATE users UPDATE users
SET login_fail_count = 0, last_login_fail = NULL, SET login_fail_count = 0, last_login_fail = NULL,