add ip log
This commit is contained in:
@@ -60,6 +60,7 @@ from .user_account_history import (
|
||||
UserAccountHistoryResp,
|
||||
UserAccountHistoryType,
|
||||
)
|
||||
from .user_login_log import UserLoginLog
|
||||
|
||||
__all__ = [
|
||||
"APIUploadedRoom",
|
||||
@@ -118,6 +119,7 @@ __all__ = [
|
||||
"UserAchievement",
|
||||
"UserAchievement",
|
||||
"UserAchievementResp",
|
||||
"UserLoginLog",
|
||||
"UserResp",
|
||||
"UserStatistics",
|
||||
"UserStatisticsResp",
|
||||
|
||||
40
app/database/user_login_log.py
Normal file
40
app/database/user_login_log.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
User Login Log Database Model
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from sqlmodel import Field, SQLModel
|
||||
|
||||
|
||||
class UserLoginLog(SQLModel, table=True):
|
||||
"""User login log table"""
|
||||
__tablename__ = "user_login_log" # pyright: ignore[reportAssignmentType]
|
||||
|
||||
id: Optional[int] = Field(default=None, primary_key=True, description="Record ID")
|
||||
user_id: int = Field(index=True, description="User ID")
|
||||
ip_address: str = Field(max_length=45, index=True, description="IP address (supports IPv4 and IPv6)")
|
||||
user_agent: Optional[str] = Field(default=None, max_length=500, description="User agent information")
|
||||
login_time: datetime = Field(default_factory=datetime.utcnow, description="Login time")
|
||||
|
||||
# GeoIP information
|
||||
country_code: Optional[str] = Field(default=None, max_length=2, description="Country code")
|
||||
country_name: Optional[str] = Field(default=None, max_length=100, description="Country name")
|
||||
city_name: Optional[str] = Field(default=None, max_length=100, description="City name")
|
||||
latitude: Optional[str] = Field(default=None, max_length=20, description="Latitude")
|
||||
longitude: Optional[str] = Field(default=None, max_length=20, description="Longitude")
|
||||
time_zone: Optional[str] = Field(default=None, max_length=50, description="Time zone")
|
||||
|
||||
# ASN information
|
||||
asn: Optional[int] = Field(default=None, description="Autonomous System Number")
|
||||
organization: Optional[str] = Field(default=None, max_length=200, description="Organization name")
|
||||
|
||||
# Login status
|
||||
login_success: bool = Field(default=True, description="Whether the login was successful")
|
||||
login_method: str = Field(max_length=50, description="Login method (password/oauth/etc.)")
|
||||
|
||||
# Additional information
|
||||
notes: Optional[str] = Field(default=None, max_length=500, description="Additional notes")
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
Reference in New Issue
Block a user