domain

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmailAlreadyTaken      = apperr.New("email_already_taken")
	ErrInvalidEmailOrPassword = apperr.New("invalid_email_or_password")
	ErrAdminAccountRequired   = errors.New(`seelf requires a default user to be created but your database looks empty.
	Please set the SEELF_ADMIN_EMAIL and SEELF_ADMIN_PASSWORD environment variables and relaunch the command, for example:

	$ SEELF_ADMIN_EMAIL=admin@example.com SEELF_ADMIN_PASSWORD=admin seelf serve

	Please note this is a one time only action`)
)
View Source
var ErrInvalidEmail = apperr.New("invalid_email")

Functions

func CurrentUser

func CurrentUser(ctx context.Context) (m monad.Maybe[UserID])

Retrieve the current user attached to the given context if any.

func WithUserID

func WithUserID(ctx context.Context, uid UserID) context.Context

Attach the given UserID to the given context. Will be used everywhere when trying to determine which user is currently executing an action.

Types

type APIKey

type APIKey string

type Email

type Email string

func EmailFrom

func EmailFrom(value string) (Email, error)

Try to constructs an email from a raw string

type KeyGenerator

type KeyGenerator interface {
	Generate() (APIKey, error)
}

type PasswordHash

type PasswordHash string

type PasswordHasher

type PasswordHasher interface {
	Hash(string) (PasswordHash, error)
	Compare(string, PasswordHash) error
}

type UniqueEmail

type UniqueEmail Email

type User

type User struct {
	event.Emitter
	// contains filtered or unexported fields
}

func NewUser

func NewUser(email UniqueEmail, password PasswordHash, key APIKey) (u User)

func UserFrom

func UserFrom(scanner storage.Scanner) (u User, err error)

Recreates a user from a storage driver

func (*User) HasEmail

func (u *User) HasEmail(email UniqueEmail)

Updates the user email

func (*User) HasPassword

func (u *User) HasPassword(password PasswordHash)

Updates the user password

func (User) ID

func (u User) ID() UserID

func (User) Password

func (u User) Password() PasswordHash

type UserEmailChanged

type UserEmailChanged struct {
	bus.Notification

	ID    UserID
	Email UniqueEmail
}

func (UserEmailChanged) Name_ added in v1.2.0

func (UserEmailChanged) Name_() string

type UserID

type UserID string

type UserPasswordChanged

type UserPasswordChanged struct {
	bus.Notification

	ID       UserID
	Password PasswordHash
}

func (UserPasswordChanged) Name_ added in v1.2.0

func (UserPasswordChanged) Name_() string

type UserRegistered

type UserRegistered struct {
	bus.Notification

	ID           UserID
	Email        UniqueEmail
	Password     PasswordHash
	Key          APIKey
	RegisteredAt time.Time
}

func (UserRegistered) Name_ added in v1.2.0

func (UserRegistered) Name_() string

type UsersReader

type UsersReader interface {
	GetUsersCount(context.Context) (uint, error)
	GetIDFromAPIKey(context.Context, APIKey) (UserID, error)
	IsEmailUnique(context.Context, Email) (UniqueEmail, error)
	IsEmailUniqueForUser(context.Context, UserID, Email) (UniqueEmail, error)
	GetByEmail(context.Context, Email) (User, error)
	GetByID(context.Context, UserID) (User, error)
}

type UsersWriter

type UsersWriter interface {
	Write(context.Context, ...*User) error
}

Jump to

Keyboard shortcuts

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