feat: 会话管理 - 支持按设备粒度踢下线
- 新增 sessions 表,每次登录创建会话记录(记录 IP/UA) - AuthMiddleware 改为基于 session 校验,可精确踢掉单个设备 - 自己改密码后踢掉其他设备,管理员改密码后踢掉该用户全部设备 - 新增 GET /api/me/sessions 查看活跃会话列表 - 新增 DELETE /api/me/sessions/:sessionId 踢掉指定会话 - 新增 DELETE /api/admin/users/:id/sessions 管理员强制下线某用户 - 兼容无 session_id 的旧 token,回退到 TokenInvalidBefore 校验
This commit is contained in:
@@ -3,13 +3,14 @@ package model
|
||||
import "time"
|
||||
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
Username string `gorm:"uniqueIndex;size:64;not null"`
|
||||
Password string `gorm:"size:128;not null"`
|
||||
Role string `gorm:"size:16;default:user"`
|
||||
Status int `gorm:"default:1"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||
Username string `gorm:"uniqueIndex;size:64;not null"`
|
||||
Password string `gorm:"size:128;not null"`
|
||||
Role string `gorm:"size:16;default:user"`
|
||||
Status int `gorm:"default:1"`
|
||||
TokenInvalidBefore *time.Time `gorm:"default:null"`
|
||||
CreatedAt time.Time `gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `gorm:"autoUpdateTime"`
|
||||
}
|
||||
|
||||
func (User) TableName() string {
|
||||
|
||||
Reference in New Issue
Block a user