update
This commit is contained in:
28
internal/model/refresh_token.go
Normal file
28
internal/model/refresh_token.go
Normal file
@ -0,0 +1,28 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// RefreshToken 刷新令牌(服务端状态),用于无状态 JWT 的续期与吊销(踢下线)。
|
||||
//
|
||||
// refresh_token 本身是随机串,这里只存其 SHA256 哈希,原始串仅返回给客户端一次。
|
||||
// revoked=1 表示已吊销(登出 / 全设备登出 / 改密)。
|
||||
type RefreshToken struct {
|
||||
ID uint64 `gorm:"primaryKey;column:id" json:"-"`
|
||||
UserID uint32 `gorm:"column:user_id;index:idx_user_id" json:"-"`
|
||||
TokenHash string `gorm:"column:token_hash;size:64;uniqueIndex:uk_token_hash" json:"-"`
|
||||
ExpiresAt uint32 `gorm:"column:expires_at" json:"-"`
|
||||
Revoked uint8 `gorm:"column:revoked" json:"-"`
|
||||
UserAgent string `gorm:"column:user_agent;size:255" json:"-"`
|
||||
IP string `gorm:"column:ip;size:64" json:"-"`
|
||||
CreatedAt uint32 `gorm:"column:created_at" json:"-"`
|
||||
|
||||
// 与 GORM 自动时间字段区分:CreatedAt 由业务层显式写入 Unix 秒。
|
||||
}
|
||||
|
||||
// TableName 指定表名。
|
||||
func (RefreshToken) TableName() string { return "refresh_tokens" }
|
||||
|
||||
// IsValid 未被吊销且未过期。
|
||||
func (r *RefreshToken) IsValid() bool {
|
||||
return r.Revoked == 0 && r.ExpiresAt >= uint32(time.Now().Unix())
|
||||
}
|
||||
Reference in New Issue
Block a user