refactor: Remove Token management and integrate Redis for authentication
- Deleted the Token model and its repository, transitioning to a Redis-based token management system. - Updated the service layer to utilize Redis for token storage, enhancing performance and scalability. - Refactored the container to remove TokenRepository and integrate the new token service. - Cleaned up the Dockerfile and other files by removing unnecessary whitespace and comments. - Enhanced error handling and logging for Redis initialization and usage.
This commit is contained in:
@@ -22,7 +22,7 @@ type yggdrasilServiceComposite struct {
|
||||
serializationService SerializationService
|
||||
certificateService CertificateService
|
||||
profileRepo repository.ProfileRepository
|
||||
tokenRepo repository.TokenRepository
|
||||
tokenService TokenService // 使用TokenService接口,不直接依赖TokenRepository
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ func NewYggdrasilServiceComposite(
|
||||
db *gorm.DB,
|
||||
userRepo repository.UserRepository,
|
||||
profileRepo repository.ProfileRepository,
|
||||
tokenRepo repository.TokenRepository,
|
||||
yggdrasilRepo repository.YggdrasilRepository,
|
||||
signatureService *SignatureService,
|
||||
redisClient *redis.Client,
|
||||
logger *zap.Logger,
|
||||
tokenService TokenService, // 新增:TokenService接口
|
||||
) YggdrasilService {
|
||||
// 创建各个专门的服务
|
||||
authService := NewYggdrasilAuthService(db, userRepo, yggdrasilRepo, logger)
|
||||
@@ -53,7 +53,7 @@ func NewYggdrasilServiceComposite(
|
||||
serializationService: serializationService,
|
||||
certificateService: certificateService,
|
||||
profileRepo: profileRepo,
|
||||
tokenRepo: tokenRepo,
|
||||
tokenService: tokenService,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -75,8 +75,8 @@ func (s *yggdrasilServiceComposite) ResetYggdrasilPassword(ctx context.Context,
|
||||
|
||||
// JoinServer 加入服务器
|
||||
func (s *yggdrasilServiceComposite) JoinServer(ctx context.Context, serverID, accessToken, selectedProfile, ip string) error {
|
||||
// 验证Token
|
||||
token, err := s.tokenRepo.FindByAccessToken(ctx, accessToken)
|
||||
// 通过TokenService验证Token并获取UUID
|
||||
uuid, err := s.tokenService.GetUUIDByAccessToken(ctx, accessToken)
|
||||
if err != nil {
|
||||
s.logger.Error("验证Token失败",
|
||||
zap.Error(err),
|
||||
@@ -87,7 +87,7 @@ func (s *yggdrasilServiceComposite) JoinServer(ctx context.Context, serverID, ac
|
||||
|
||||
// 格式化UUID并验证与Token关联的配置文件
|
||||
formattedProfile := utils.FormatUUID(selectedProfile)
|
||||
if token.ProfileId != formattedProfile {
|
||||
if uuid != formattedProfile {
|
||||
return errors.New("selectedProfile与Token不匹配")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user