20260203_add_login_attempts_and_configs.sql 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- 创建登录尝试记录表
  2. -- 用于记录登录失败次数,支持账号锁定功能
  3. -- 与技术方案中的 max_login_attempts 和 login_lockout_minutes 配置对应
  4. CREATE TABLE IF NOT EXISTS login_attempts (
  5. id INT AUTO_INCREMENT PRIMARY KEY COMMENT '主键ID',
  6. -- 基本信息
  7. username VARCHAR(100) NOT NULL COMMENT '用户名',
  8. success TINYINT(1) DEFAULT 0 COMMENT '是否成功: 1-成功, 0-失败',
  9. -- 登录环境信息
  10. machine_code VARCHAR(255) COMMENT '机器码',
  11. ip_address VARCHAR(45) COMMENT 'IP地址',
  12. user_agent VARCHAR(500) COMMENT '用户代理',
  13. failure_reason VARCHAR(255) COMMENT '失败原因',
  14. -- 时间戳
  15. attempted_at DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '尝试时间',
  16. -- 索引
  17. INDEX idx_login_attempt_user (username),
  18. INDEX idx_login_attempt_time (attempted_at),
  19. INDEX idx_login_attempt_user_time (username, attempted_at)
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='登录尝试记录表';
  21. -- 初始化客户端核心配置项
  22. INSERT INTO system_config (config_key, config_value, config_type, app_name, description, is_system, is_editable) VALUES
  23. -- 心跳相关配置
  24. ('heartbeat_interval_seconds', '10', 'int', 'backend-client', '心跳检测间隔秒数', 1, 1),
  25. ('max_heartbeat_failures', '100', 'int', 'backend-client', '心跳最大失败次数', 1, 1),
  26. -- Session自动续期配置
  27. ('session_renewal_threshold', '1800', 'int', 'backend-client', 'Session续期阈值(秒),剩余时间小于此值时触发续期', 1, 1),
  28. ('session_extension_duration', '3600', 'int', 'backend-client', 'Session延长时间(秒),续期时延长的时长', 1, 1),
  29. ('session_default_expiry_seconds', '86400', 'int', 'backend-client', 'Session默认有效期(秒),新登录时创建的有效期', 1, 1),
  30. -- 安全相关配置
  31. ('timestamp_tolerance_seconds', '300', 'int', 'backend-client', '时间戳容忍秒数(±5分钟)', 1, 1),
  32. ('prevent_duplicate_login', 'true', 'bool', 'backend-client', '是否防止重复登录', 1, 1),
  33. -- 登录相关配置
  34. ('max_login_attempts', '5', 'int', 'backend-client', '最大登录失败次数', 1, 1),
  35. ('login_lockout_minutes', '60', 'int', 'backend-client', '登录锁定分钟数', 1, 1),
  36. -- 公告相关配置
  37. ('announcement_cache_seconds', '300', 'int', 'backend-client', '公告缓存秒数', 1, 1),
  38. -- 密钥相关配置
  39. ('key_sync_interval_seconds', '60', 'int', 'backend-client', '密钥同步间隔秒数', 1, 1)
  40. ON DUPLICATE KEY UPDATE description=VALUES(description);
  41. -- 初始化默认软件
  42. INSERT INTO software (code, name, daily_price, is_active) VALUES
  43. ('buff-xp-steam-sh', '游铛铛(BUFF选品和Steam扫货工具)', 1, 1)
  44. ON DUPLICATE KEY UPDATE name=VALUES(name), daily_price=VALUES(daily_price);