websessions

package
v0.0.0-...-059fb3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingSessionToken = errors.New("missing session token")
	ErrSessionNotFound     = errors.New("session not found")
)
View Source
var (
	AliceWebSessionExample = Session{
							// contains filtered or unexported fields
	}

	BobWebSessionExample = Session{
							// contains filtered or unexported fields
	}
)
View Source
var ErrUserIDNotMatching = errors.New("user ids are not matching")

Functions

This section is empty.

Types

type CreateCmd

type CreateCmd struct {
	UserID     uuid.UUID
	UserAgent  string
	RemoteAddr string
}

func (CreateCmd) Validate

func (t CreateCmd) Validate() error

type DeleteCmd

type DeleteCmd struct {
	UserID uuid.UUID
	Token  secret.Text
}

func (DeleteCmd) Validate

func (t DeleteCmd) Validate() error

type FakeSessionBuilder

type FakeSessionBuilder struct {
	// contains filtered or unexported fields
}

func NewFakeSession

func NewFakeSession(t *testing.T) *FakeSessionBuilder

func (*FakeSessionBuilder) Build

func (f *FakeSessionBuilder) Build() *Session

func (*FakeSessionBuilder) CreatedAt

func (f *FakeSessionBuilder) CreatedAt(at time.Time) *FakeSessionBuilder

func (*FakeSessionBuilder) CreatedBy

func (f *FakeSessionBuilder) CreatedBy(user *users.User) *FakeSessionBuilder

func (*FakeSessionBuilder) WithDevice

func (f *FakeSessionBuilder) WithDevice(device string) *FakeSessionBuilder

func (*FakeSessionBuilder) WithIP

func (*FakeSessionBuilder) WithToken

func (f *FakeSessionBuilder) WithToken(token string) *FakeSessionBuilder

type MockService

type MockService struct {
	mock.Mock
}

MockService is an autogenerated mock type for the Service type

func NewMockService

func NewMockService(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockService

NewMockService creates a new instance of MockService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockService) Create

func (_m *MockService) Create(ctx context.Context, cmd *CreateCmd) (*Session, error)

Create provides a mock function with given fields: ctx, cmd

func (*MockService) Delete

func (_m *MockService) Delete(ctx context.Context, cmd *DeleteCmd) error

Delete provides a mock function with given fields: ctx, cmd

func (*MockService) DeleteAll

func (_m *MockService) DeleteAll(ctx context.Context, userID uuid.UUID) error

DeleteAll provides a mock function with given fields: ctx, userID

func (*MockService) GetAllForUser

func (_m *MockService) GetAllForUser(ctx context.Context, userID uuid.UUID, cmd *sqlstorage.PaginateCmd) ([]Session, error)

GetAllForUser provides a mock function with given fields: ctx, userID, cmd

func (*MockService) GetByToken

func (_m *MockService) GetByToken(ctx context.Context, token secret.Text) (*Session, error)

GetByToken provides a mock function with given fields: ctx, token

func (*MockService) GetFromReq

func (_m *MockService) GetFromReq(r *http.Request) (*Session, error)

GetFromReq provides a mock function with given fields: r

func (*MockService) Logout

func (_m *MockService) Logout(r *http.Request, w http.ResponseWriter) error

Logout provides a mock function with given fields: r, w

type Service

type Service interface {
	Create(ctx context.Context, cmd *CreateCmd) (*Session, error)
	GetByToken(ctx context.Context, token secret.Text) (*Session, error)
	GetFromReq(r *http.Request) (*Session, error)
	Logout(r *http.Request, w http.ResponseWriter) error
	GetAllForUser(ctx context.Context, userID uuid.UUID, cmd *sqlstorage.PaginateCmd) ([]Session, error)
	Delete(ctx context.Context, cmd *DeleteCmd) error
	DeleteAll(ctx context.Context, userID uuid.UUID) error
}

func Init

func Init(tools tools.Tools, db *sql.DB) Service

type Session

type Session struct {
	// contains filtered or unexported fields
}

func (*Session) CreatedAt

func (s *Session) CreatedAt() time.Time

func (*Session) Device

func (s *Session) Device() string

func (*Session) IP

func (s *Session) IP() string

func (*Session) Token

func (s *Session) Token() secret.Text

func (*Session) UserID

func (s *Session) UserID() uuid.UUID

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL