Files
RenewCMS/internal/infrastructure/useCases/RevokeSession.go
T

33 lines
787 B
Go

package useCases
import (
"RenewCMS/internal/domain/session"
"time"
)
type SessionRevocationUseCase struct {
sessions session.Repository
now func() time.Time
}
func NewSessionRevocationUseCase(sessions session.Repository, now func() time.Time) *SessionRevocationUseCase {
return &SessionRevocationUseCase{sessions, now}
}
func (s *SessionRevocationUseCase) Revoke(id string, expiresAt time.Time) error {
if err := session.ValidateID(id); err != nil {
return err
}
if !expiresAt.After(s.now()) {
return nil
}
return s.sessions.Revoke(session.Revocation{ID: id, ExpiresAt: expiresAt})
}
func (s *SessionRevocationUseCase) IsRevoked(id string) (bool, error) {
if err := session.ValidateID(id); err != nil {
return false, err
}
return s.sessions.IsRevoked(id)
}