- Implement extensible hook system for content moderation with builtin and AI-powered moderation hooks - Add QR code login feature with SSE for real-time status updates and scan/confirm/cancel workflow - Introduce layered cache with local LRU + Redis backend for improved read performance - Refactor post and comment services to use hook-based moderation instead of direct AI service calls - Add local cache configuration options (size, buckets, ttl)
89 lines
2.9 KiB
Go
89 lines
2.9 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// LoginEvent 登录事件
|
|
type LoginEvent string
|
|
|
|
const (
|
|
LoginEventLogin LoginEvent = "login"
|
|
LoginEventLogout LoginEvent = "logout"
|
|
LoginEventRefresh LoginEvent = "refresh"
|
|
LoginEventReset LoginEvent = "reset"
|
|
LoginEventFail LoginEvent = "fail"
|
|
)
|
|
|
|
// LoginResult 登录结果
|
|
type LoginResult string
|
|
|
|
const (
|
|
LoginResultSuccess LoginResult = "success"
|
|
LoginResultFail LoginResult = "fail"
|
|
)
|
|
|
|
// FailReason 失败原因
|
|
type FailReason string
|
|
|
|
const (
|
|
FailReasonUserNotFound FailReason = "user_not_found"
|
|
FailReasonWrongPassword FailReason = "wrong_password"
|
|
FailReasonAccountLocked FailReason = "account_locked"
|
|
FailReasonAccountBanned FailReason = "account_banned"
|
|
FailReasonRateLimit FailReason = "rate_limit"
|
|
FailReasonInvalidToken FailReason = "invalid_token"
|
|
FailReasonTokenExpired FailReason = "token_expired"
|
|
FailReasonInvalidCode FailReason = "invalid_code"
|
|
FailReasonCodeExpired FailReason = "code_expired"
|
|
FailReasonUnknown FailReason = "unknown"
|
|
)
|
|
|
|
// LoginType 登录类型
|
|
type LoginType string
|
|
|
|
const (
|
|
LoginTypePassword LoginType = "password"
|
|
LoginTypeSMS LoginType = "sms"
|
|
LoginTypeEmail LoginType = "email"
|
|
LoginTypeOAuth LoginType = "oauth"
|
|
LoginTypeQRCode LoginType = "qrcode"
|
|
)
|
|
|
|
// LoginMethod 登录方式
|
|
type LoginMethod string
|
|
|
|
const (
|
|
LoginMethodUsername LoginMethod = "username"
|
|
LoginMethodMobile LoginMethod = "mobile"
|
|
LoginMethodEmail LoginMethod = "email"
|
|
)
|
|
|
|
// LoginLog 登录日志实体
|
|
type LoginLog struct {
|
|
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
UserID string `json:"user_id" gorm:"type:varchar(36);index:idx_user"`
|
|
UserName string `json:"user_name" gorm:"type:varchar(100)"`
|
|
NickName string `json:"nick_name" gorm:"type:varchar(100)"`
|
|
LoginType string `json:"login_type" gorm:"type:varchar(20);index:idx_login_type"`
|
|
LoginMethod string `json:"login_method" gorm:"type:varchar(20)"`
|
|
Event string `json:"event" gorm:"type:varchar(20);index:idx_event"`
|
|
IP string `json:"ip" gorm:"type:varchar(45);index:idx_ip"`
|
|
IPLocation string `json:"ip_location" gorm:"type:varchar(100)"`
|
|
UserAgent string `json:"user_agent" gorm:"type:varchar(500)"`
|
|
DeviceType string `json:"device_type" gorm:"type:varchar(20)"`
|
|
DeviceID string `json:"device_id" gorm:"type:varchar(100)"`
|
|
AppVersion string `json:"app_version" gorm:"type:varchar(50)"`
|
|
Result string `json:"result" gorm:"type:varchar(20);index:idx_result"`
|
|
FailReason string `json:"fail_reason" gorm:"type:varchar(200)"`
|
|
TokenID string `json:"token_id" gorm:"type:varchar(64)"`
|
|
ExpiredAt *time.Time `json:"expired_at"`
|
|
ServerIP string `json:"server_ip" gorm:"type:varchar(45)"`
|
|
ServerPort int `json:"server_port" gorm:"type:int"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"index:idx_created"`
|
|
}
|
|
|
|
func (LoginLog) TableName() string {
|
|
return "login_logs"
|
|
}
|