Merge remote-tracking branch 'origin/feature/redis-auth-integration' into dev
# Conflicts: # go.mod # go.sum # internal/container/container.go # internal/repository/interfaces.go # internal/service/mocks_test.go # internal/service/texture_service_test.go # internal/service/token_service_test.go # pkg/redis/manager.go
This commit is contained in:
@@ -29,3 +29,10 @@ func (Client) TableName() string {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// Token Yggdrasil 认证令牌模型
|
||||
type Token struct {
|
||||
AccessToken string `gorm:"column:access_token;type:text;primaryKey" json:"access_token"` // 改为text以支持JWT长度
|
||||
UserID int64 `gorm:"column:user_id;not null;index:idx_tokens_user_id" json:"user_id"`
|
||||
ClientToken string `gorm:"column:client_token;type:varchar(64);not null;index:idx_tokens_client_token" json:"client_token"`
|
||||
ProfileId string `gorm:"column:profile_id;type:varchar(36);index:idx_tokens_profile_id" json:"profile_id"` // 改为可空
|
||||
Version int `gorm:"column:version;not null;default:0;index:idx_tokens_version" json:"version"` // 新增:版本号
|
||||
Usable bool `gorm:"column:usable;not null;default:true;index:idx_tokens_usable" json:"usable"`
|
||||
IssueDate time.Time `gorm:"column:issue_date;type:timestamp;not null;default:CURRENT_TIMESTAMP;index:idx_tokens_issue_date,sort:desc" json:"issue_date"`
|
||||
ExpiresAt *time.Time `gorm:"column:expires_at;type:timestamp" json:"expires_at,omitempty"` // 新增:过期时间
|
||||
StaleAt *time.Time `gorm:"column:stale_at;type:timestamp" json:"stale_at,omitempty"` // 新增:过期但可用时间
|
||||
|
||||
// 关联
|
||||
User *User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
|
||||
Profile *Profile `gorm:"foreignKey:ProfileId;references:UUID;constraint:OnDelete:CASCADE" json:"profile,omitempty"`
|
||||
}
|
||||
|
||||
// TableName 指定表名
|
||||
func (Token) TableName() string { return "tokens" }
|
||||
18
internal/model/yggdrasil_test.go
Normal file
18
internal/model/yggdrasil_test.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGenerateRandomPassword(t *testing.T) {
|
||||
pwd := GenerateRandomPassword(16)
|
||||
if len(pwd) != 16 {
|
||||
t.Fatalf("length mismatch: %d", len(pwd))
|
||||
}
|
||||
for _, ch := range pwd {
|
||||
if !strings.ContainsRune(passwordChars, ch) {
|
||||
t.Fatalf("unexpected char: %c", ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user