account

package
v0.0.0-...-e1e9d1d Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package account defines the standard interface to manage user accounts.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	// ID returns the unique id of the account. Its format is
	// implementation-dependent.
	ID() string

	// Email returns the email address of this account.
	Email() string

	// Groups returns the list of groups this account belongs to.
	Groups() []string

	// UnmarshalProfile unmarshals the arbitrary profile data associated
	// with this account into dst.
	UnmarshalProfile(dst interface{}) error

	// ChangeGroups alters the groups of the account, adding the add groups
	// first and removing the rm groups next, so if the same group is in
	// both lists then it will get removed.
	ChangeGroups(ctx context.Context, add, rm []string) error

	// ChangeEmail updates the account's email to newEmail and immediately
	// marks it as verified, as this should only be called after the
	// verification process has been completed successfully.
	ChangeEmail(ctx context.Context, newEmail string) error

	// ChangePassword updates the account's password to newPwd.
	ChangePassword(ctx context.Context, newPwd string) error

	// MarkEmailVerified marks the email of the account as verified.
	MarkEmailVerified(context.Context) error

	// Delete deletes the account.
	Delete(context.Context) error
}

Account defines the method required to implement an Account.

type MockAccount

type MockAccount struct {
	IDFunc                func() string
	EmailFunc             func() string
	GroupsFunc            func() []string
	UnmarshalProfileFunc  func(interface{}) error
	ChangeGroupsFunc      func(context.Context, []string, []string) error
	ChangeEmailFunc       func(context.Context, string) error
	ChangePasswordFunc    func(context.Context, string) error
	MarkEmailVerifiedFunc func(context.Context) error
	DeleteFunc            func(context.Context) error
}

MockAccount is a test mock for the Account interface.

func (*MockAccount) ChangeEmail

func (m *MockAccount) ChangeEmail(ctx context.Context, newEmail string) error

func (*MockAccount) ChangeGroups

func (m *MockAccount) ChangeGroups(ctx context.Context, add, rm []string) error

func (*MockAccount) ChangePassword

func (m *MockAccount) ChangePassword(ctx context.Context, newPwd string) error

func (*MockAccount) Delete

func (m *MockAccount) Delete(ctx context.Context) error

func (*MockAccount) Email

func (m *MockAccount) Email() string

func (*MockAccount) Groups

func (m *MockAccount) Groups() []string

func (*MockAccount) ID

func (m *MockAccount) ID() string

func (*MockAccount) MarkEmailVerified

func (m *MockAccount) MarkEmailVerified(ctx context.Context) error

func (*MockAccount) UnmarshalProfile

func (m *MockAccount) UnmarshalProfile(dst interface{}) error

type MockProvider

type MockProvider struct {
	NewFunc        func(context.Context, string, string, []string, interface{}) (Account, error)
	GetByIDFunc    func(context.Context, string, string) (Account, error)
	GetByEmailFunc func(context.Context, string, string) (Account, error)
}

MockProvider is a test mock for the Provider interface.

func (*MockProvider) GetByEmail

func (m *MockProvider) GetByEmail(ctx context.Context, email, rawPwd string) (Account, error)

func (*MockProvider) GetByID

func (m *MockProvider) GetByID(ctx context.Context, id, rawPwd string) (Account, error)

func (*MockProvider) New

func (m *MockProvider) New(ctx context.Context, email, rawPwd string, groups []string, profile interface{}) (Account, error)

type Provider

type Provider interface {
	// New creates a new account. The profile is an arbitrary value associated
	// with the account, how it is stored and retrieved is
	// implementation-dependent.
	New(ctx context.Context, email, rawPwd string, groups []string, profile interface{}) (Account, error)

	// GetByID retrieves the Account by its id. If rawPwd is not empty, it
	// must match the account's password  otherwise an authentication error
	// is returned.
	GetByID(ctx context.Context, id, rawPwd string) (Account, error)

	// GetByEmail retrieves the Account by its email. If rawPwd is not empty,
	// it must match the account's password otherwise an authentication
	// error is returned.
	GetByEmail(ctx context.Context, email, rawPwd string) (Account, error)
}

Provider defines the methods to create, get and authenticate accounts.

Jump to

Keyboard shortcuts

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