user

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound                     error = errors.New("not found")
	ErrDisplayNameRequired          error = errors.New("display name required")
	ErrEmailAlreadyRegistered       error = errors.New("email already registered")
	ErrEmailRequired                error = errors.New("email required")
	ErrNickNameAlreadyRegistered    error = errors.New("nickname already registered")
	ErrNickNameInvalid              error = errors.New("invalid nickname")
	ErrNickNameRequired             error = errors.New("nickname required")
	ErrPasswordConfirmationMismatch error = errors.New("new password and confirmation do not match")
	ErrPasswordHashRequired         error = errors.New("password hash required")
	ErrPasswordIncorrect            error = errors.New("incorrect password")
	ErrPasswordRequired             error = errors.New("password required")
	ErrUUIDRequired                 error = errors.New("UUID required")
)

Functions

This section is empty.

Types

type FakeRepository

type FakeRepository struct {
	// TODO refactor with map[uuid]User
	Users []User
}

func (*FakeRepository) UserAdd

func (r *FakeRepository) UserAdd(user User) error

func (*FakeRepository) UserDeleteByUUID

func (r *FakeRepository) UserDeleteByUUID(userUUID string) error

func (*FakeRepository) UserGetAll

func (r *FakeRepository) UserGetAll() ([]User, error)

func (*FakeRepository) UserGetByEmail

func (r *FakeRepository) UserGetByEmail(email string) (User, error)

func (*FakeRepository) UserGetByNickName

func (r *FakeRepository) UserGetByNickName(nick string) (User, error)

func (*FakeRepository) UserGetByUUID

func (r *FakeRepository) UserGetByUUID(userUUID string) (User, error)

func (*FakeRepository) UserIsEmailRegistered

func (r *FakeRepository) UserIsEmailRegistered(email string) (bool, error)

func (*FakeRepository) UserIsNickNameRegistered

func (r *FakeRepository) UserIsNickNameRegistered(nick string) (bool, error)

func (*FakeRepository) UserUpdate

func (r *FakeRepository) UserUpdate(user User) error

func (*FakeRepository) UserUpdateInfo

func (r *FakeRepository) UserUpdateInfo(info InfoUpdate) error

func (*FakeRepository) UserUpdatePasswordHash

func (r *FakeRepository) UserUpdatePasswordHash(passwordHash PasswordHashUpdate) error

type InfoUpdate

type InfoUpdate struct {
	UUID        string
	Email       string
	NickName    string
	DisplayName string
	UpdatedAt   time.Time
}

InfoUpdate represents an account information update for an authenticated user.

type PasswordHashUpdate

type PasswordHashUpdate struct {
	UUID         string
	PasswordHash string
	UpdatedAt    time.Time
}

PasswordHashUpdate represents a password hash change for an authenticated user.

type PasswordUpdate

type PasswordUpdate struct {
	UUID                    string
	CurrentPassword         string
	NewPassword             string
	NewPasswordConfirmation string
}

PasswordHashUpdate represents a password change for an authenticated user.

type Repository

type Repository interface {
	// UserAdd saves a new user.
	UserAdd(User) error

	// UserDelete deletes an existing user and all related data.
	UserDeleteByUUID(uuid string) error

	// UserGetAll returns a list of all User accounts.
	UserGetAll() ([]User, error)

	// UserGetByEmail returns the User registered with a given email address.
	UserGetByEmail(email string) (User, error)

	// UserGetByNickName returns the User registered with a given nickname.
	UserGetByNickName(nick string) (User, error)

	// UserGetByUUID returns the User corresponding to a given UUID.
	UserGetByUUID(string) (User, error)

	// UserIsEmailRegistered returns whether there is an existing user
	// registered with this email address.
	UserIsEmailRegistered(email string) (bool, error)

	// UserIsNickNameRegistered returns whether there is an existing user
	// registered with this nickname.
	UserIsNickNameRegistered(nick string) (bool, error)

	// UserUpdate updates an existing user.
	UserUpdate(User) error

	// UserUpdateInfo updates an existing user's account information.
	UserUpdateInfo(InfoUpdate) error

	// UserUpdatePasswordHash updates an existing user's account password hash.
	UserUpdatePasswordHash(PasswordHashUpdate) error
}

Repository provides access to the User repository.

type Service

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

Service handles operations for the user domain.

func NewService

func NewService(r Repository) *Service

NewService initializes and returns a User Service.

func (*Service) Add

func (s *Service) Add(user User) error

Add adds a new User.

func (*Service) All

func (s *Service) All() ([]User, error)

All returns a list of all users.

func (*Service) Authenticate

func (s *Service) Authenticate(email, password string) (User, error)

Authenticate checks user-submitted credentials to determine whether a user submitted the correct login information.

func (*Service) ByNickName

func (s *Service) ByNickName(nick string) (User, error)

ByNickName returns the user corresponding to a given NickName.

func (*Service) ByUUID

func (s *Service) ByUUID(userUUID string) (User, error)

ByUUID returns the user corresponding to a given UUID.

func (*Service) DeleteByUUID

func (s *Service) DeleteByUUID(userUUID string) error

DeleteByUUID deletes an existing user and all related data.

func (*Service) Update

func (s *Service) Update(user User) error

Update updates an existing user.

func (*Service) UpdateInfo

func (s *Service) UpdateInfo(info InfoUpdate) error

UpdateInfo updates an existing user's account information.

func (*Service) UpdatePassword

func (s *Service) UpdatePassword(passwordUpdate PasswordUpdate) error

UpdatePassword updates an existing user's password.

func (*Service) UpdatePasswordHash

func (s *Service) UpdatePasswordHash(user User) error

UpdatePasswordHash updates an existing user's password hash.

type User

type User struct {
	// UUID is the internal identifier for this User.
	UUID string

	// Email is the identifier a User logs in with.
	Email string

	// NickName is the handle used in user-specific URLs, and may only contain
	// alphanumerical characters, the dash character, or the underscore character.
	NickName string

	// DisplayName is the handle used in the Web interface for this User.
	DisplayName string

	// Password is the clear-text password for this User, that will be set when
	// creating or updating the User, and cleared once it has been hashed.
	Password string

	// PasswordHash contains the securely hashed password for this User.
	PasswordHash string

	// IsAdmin represents whether this User has administration privileges.
	IsAdmin bool

	CreatedAt time.Time
	UpdatedAt time.Time
}

User represents a registered user.

Jump to

Keyboard shortcuts

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