This commit is contained in:
2026-08-16 15:11:38 +08:00
parent f7f6db8695
commit a85477be80
40 changed files with 761 additions and 144 deletions
+4 -1
View File
@@ -111,6 +111,10 @@ func (uc *AuthenticationUsecase) Login(ctx context.Context, attempt *LoginAttemp
if err != nil {
return nil, fmt.Errorf("%w: %v", ErrTokenIssue, err)
}
// Record a successful credential login immediately after issuing the JWT.
// Multipoint-session persistence happens afterwards, so a Redis/cache
// failure must not erase the successful-login audit event.
uc.recordLogin(ctx, attempt, true, "登录成功", user.ID)
if uc.security.UseMultipoint() {
oldToken, cacheErr := uc.security.ActiveToken(ctx, user.Username)
if cacheErr != nil {
@@ -123,7 +127,6 @@ func (uc *AuthenticationUsecase) Login(ctx context.Context, attempt *LoginAttemp
return nil, fmt.Errorf("%w: %v", ErrLoginState, cacheErr)
}
}
uc.recordLogin(ctx, attempt, true, "登录成功", user.ID)
return &AuthenticationResult{User: user, Token: issued.Value, ExpiresAt: issued.ExpiresAt, NeedChangePassword: user.MustChangePassword}, nil
}