Merge branch 'develop' into feature/auth-management-system
This commit is contained in:
114
backend/internal/models/auth.go
Normal file
114
backend/internal/models/auth.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// AuthToken 认证令牌模型
|
||||
type AuthToken struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
TenantID uint `gorm:"not null;index" json:"tenant_id"`
|
||||
UserID uint `gorm:"not null;index" json:"user_id"`
|
||||
|
||||
// 令牌信息
|
||||
Token string `gorm:"size:512;not null;uniqueIndex" json:"token"`
|
||||
TokenType string `gorm:"size:20;not null" json:"token_type"` // access, refresh
|
||||
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
|
||||
|
||||
// 设备信息
|
||||
DeviceID string `gorm:"size:100" json:"device_id"`
|
||||
DeviceName string `gorm:"size:100" json:"device_name"`
|
||||
DeviceType string `gorm:"size:50" json:"device_type"` // web, mobile, desktop
|
||||
IPAddress string `gorm:"size:45" json:"ip_address"`
|
||||
UserAgent string `gorm:"type:text" json:"user_agent"`
|
||||
|
||||
// 状态
|
||||
IsRevoked bool `gorm:"default:false" json:"is_revoked"`
|
||||
RevokedAt *time.Time `json:"revoked_at"`
|
||||
RevokedReason string `gorm:"size:200" json:"revoked_reason"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Tenant Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"`
|
||||
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
// LoginAttempt 登录尝试记录
|
||||
type LoginAttempt struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
TenantID uint `gorm:"not null;index" json:"tenant_id"`
|
||||
UserID *uint `gorm:"index" json:"user_id"`
|
||||
|
||||
// 尝试信息
|
||||
Username string `gorm:"size:100" json:"username"`
|
||||
Email string `gorm:"size:100" json:"email"`
|
||||
IPAddress string `gorm:"size:45;not null" json:"ip_address"`
|
||||
UserAgent string `gorm:"type:text" json:"user_agent"`
|
||||
|
||||
// 结果
|
||||
Success bool `gorm:"not null" json:"success"`
|
||||
FailureReason string `gorm:"size:200" json:"failure_reason"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// 关联
|
||||
Tenant Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"`
|
||||
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
// PasswordReset 密码重置请求
|
||||
type PasswordReset struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
TenantID uint `gorm:"not null;index" json:"tenant_id"`
|
||||
UserID uint `gorm:"not null;index" json:"user_id"`
|
||||
|
||||
// 重置信息
|
||||
Token string `gorm:"size:100;not null;uniqueIndex" json:"token"`
|
||||
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
|
||||
|
||||
// 状态
|
||||
IsUsed bool `gorm:"default:false" json:"is_used"`
|
||||
UsedAt *time.Time `json:"used_at"`
|
||||
IPAddress string `gorm:"size:45" json:"ip_address"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// 关联
|
||||
Tenant Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"`
|
||||
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
|
||||
// Session 用户会话
|
||||
type Session struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
TenantID uint `gorm:"not null;index" json:"tenant_id"`
|
||||
UserID uint `gorm:"not null;index" json:"user_id"`
|
||||
|
||||
// 会话信息
|
||||
SessionID string `gorm:"size:100;not null;uniqueIndex" json:"session_id"`
|
||||
ExpiresAt time.Time `gorm:"not null" json:"expires_at"`
|
||||
|
||||
// 设备信息
|
||||
DeviceID string `gorm:"size:100" json:"device_id"`
|
||||
DeviceName string `gorm:"size:100" json:"device_name"`
|
||||
DeviceType string `gorm:"size:50" json:"device_type"`
|
||||
IPAddress string `gorm:"size:45" json:"ip_address"`
|
||||
UserAgent string `gorm:"type:text" json:"user_agent"`
|
||||
|
||||
// 活动信息
|
||||
LastActivity time.Time `json:"last_activity"`
|
||||
IsActive bool `gorm:"default:true" json:"is_active"`
|
||||
|
||||
// 时间戳
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联
|
||||
Tenant Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"`
|
||||
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user