34 lines
1.5 KiB
Go
34 lines
1.5 KiB
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// User 管理员用户模型(单 Admin 表,无 RBAC 多角色) // Logan.Li
|
|
type User struct {
|
|
ID uint `json:"id" gorm:"primaryKey"`
|
|
Username string `json:"username" gorm:"size:100;uniqueIndex;not null"`
|
|
Password string `json:"-" gorm:"size:255;not null"` // bcrypt 哈希,JSON 响应时隐藏
|
|
Email string `json:"email" gorm:"size:100"`
|
|
Avatar string `json:"avatar" gorm:"size:500"`
|
|
Role string `json:"role" gorm:"size:20;default:'admin'"` // 固定 admin,预留扩展
|
|
IsActive bool `json:"is_active" gorm:"default:true"`
|
|
LastLogin *time.Time `json:"last_login,omitempty"`
|
|
// 会话失效基线:签发时间早于该值的 JWT 一律拒绝(改密码时刷新为当前时间)。
|
|
// 零值表示未设置过,不拦截旧令牌;SQLite 不允许 ADD COLUMN 带非常量默认值,故不用 DEFAULT CURRENT_TIMESTAMP // Logan.Li
|
|
TokenValidAfter time.Time `json:"-"`
|
|
// 账号级登录防护:连续失败计数与锁定截止时间 // Logan.Li
|
|
FailedLoginAttempts int `json:"-" gorm:"default:0"`
|
|
LockedUntil *time.Time `json:"-"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `json:"deleted_at,omitempty" gorm:"index"`
|
|
}
|
|
|
|
// TableName 指定表名 // Logan.Li
|
|
func (User) TableName() string {
|
|
return "users"
|
|
}
|