"""检查用户密码和锁定状态"""
import mysql.connector

conn = mysql.connector.connect(
    host="mysql.eazygame.cn",
    port=14013,
    user="root",
    password="wx1998WX",
    database="next_edu"
)
cursor = conn.cursor()

# 检查用户密码
cursor.execute("""
    SELECT email, password, onboarded_at
    FROM users
    WHERE email IN ('admin@xiaoxue.edu.cn', 't_chinese_1@xiaoxue.edu.cn',
                     'student_g1c1_1@xiaoxue.edu.cn', 'parent_g1c1_1@xiaoxue.edu.cn')
""")
users = cursor.fetchall()
print("=== 用户密码和 onboarding 状态 ===")
for u in users:
    has_pwd = "YES" if u[1] else "NO"
    pwd_prefix = u[1][:20] if u[1] else "NULL"
    onboarded = "YES" if u[2] else "NO"
    print(f"  {u[0]}: password={has_pwd} ({pwd_prefix}...), onboarded={onboarded}")

# 检查密码安全表
try:
    cursor.execute("""
        SELECT ps.user_id, u.email, ps.failed_login_attempts, ps.locked_until
        FROM password_security ps
        JOIN users u ON ps.user_id = u.id
        WHERE u.email IN ('admin@xiaoxue.edu.cn', 't_chinese_1@xiaoxue.edu.cn',
                          'student_g1c1_1@xiaoxue.edu.cn', 'parent_g1c1_1@xiaoxue.edu.cn')
    """)
    security = cursor.fetchall()
    print("\n=== 密码安全状态 ===")
    for s in security:
        print(f"  {s[1]}: failed_attempts={s[2]}, locked_until={s[3]}")
except Exception as e:
    print(f"\n密码安全表查询失败: {e}")

# 检查 login_logs 表最近的登录记录
try:
    cursor.execute("""
        SELECT user_email, action, status, error_message, created_at
        FROM login_logs
        ORDER BY created_at DESC
        LIMIT 20
    """)
    logs = cursor.fetchall()
    print("\n=== 最近的登录记录 ===")
    for l in logs:
        print(f"  {l[4]} | {l[0]} | {l[1]} | {l[2]} | {l[3] or ''}")
except Exception as e:
    print(f"\n登录记录查询失败: {e}")

cursor.close()
conn.close()
