| 12345678910111213141516171819202122232425262728 |
- """
- 登录尝试记录模型
- 用于记录登录失败次数,支持账号锁定功能
- """
- from datetime import datetime
- from app.utils.timezone import beijing_now_naive
- from sqlalchemy import Column, Integer, String, DateTime, Boolean
- from app.database import Base
- class LoginAttempt(Base):
- """
- 登录尝试记录表
- 用于记录每次登录尝试(成功/失败),支持登录失败次数限制和账号锁定
- """
- __tablename__ = "login_attempts"
- id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
- username = Column(String(100), nullable=False, index=True, comment="用户名")
- success = Column(Boolean, default=False, comment="是否成功: 1-成功, 0-失败")
- machine_code = Column(String(255), nullable=True, comment="机器码")
- ip_address = Column(String(45), nullable=True, comment="IP地址")
- user_agent = Column(String(500), nullable=True, comment="用户代理")
- failure_reason = Column(String(255), nullable=True, comment="失败原因")
- attempted_at = Column(DateTime, default=beijing_now_naive, index=True, comment="尝试时间")
- def __repr__(self):
- return f"<LoginAttempt(id={self.id}, username='{self.username}', success={self.success}, attempted_at={self.attempted_at})>"
|