user

package
v0.0.0-...-3dc0db1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PasswordMinEntropyBits represents the minimum amount of entropy bits
	// required for a password.
	PasswordMinEntropyBits = 50
)

Variables

View Source
var (
	// ErrInvalidDeleteUserCode indicates that the delete user code provided is
	// not valid.
	ErrInvalidDeleteUserCode = errors.New("invalid delete user code")

	// ErrInvalidPassword indicates that the password provided is not valid.
	ErrInvalidPassword = errors.New("invalid password")

	// ErrInvalidPasswordResetCode indicates that the password reset code
	// provided is not valid.
	ErrInvalidPasswordResetCode = errors.New("invalid password reset code")

	// ErrNotFound indicates that the user does not exist.
	ErrNotFound = errors.New("user not found")
)

Functions

This section is empty.

Types

type Manager

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

Manager provides an API to manage users.

func NewManager

func NewManager(cfg *viper.Viper, db hub.DB, es hub.EmailSender) *Manager

NewManager creates a new Manager instance.

func (*Manager) ApproveSession

func (m *Manager) ApproveSession(ctx context.Context, sessionID, passcode string) error

ApproveSession approves a given session using the TFA passcode provided.

func (*Manager) CheckAvailability

func (m *Manager) CheckAvailability(ctx context.Context, resourceKind, value string) (bool, error)

CheckAvailability checks the availability of a given value for the provided resource kind.

func (*Manager) CheckCredentials

func (m *Manager) CheckCredentials(
	ctx context.Context,
	email,
	password string,
) (*hub.CheckCredentialsOutput, error)

CheckCredentials checks if the credentials provided are valid.

func (*Manager) CheckSession

func (m *Manager) CheckSession(
	ctx context.Context,
	sessionID string,
	duration time.Duration,
) (*hub.CheckSessionOutput, error)

CheckSession checks if the user session provided is valid.

func (*Manager) DeleteSession

func (m *Manager) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession deletes a user session from the database.

func (*Manager) DeleteUser

func (m *Manager) DeleteUser(ctx context.Context, code string) error

DeleteUser deletes a user account from the database. The confirmation code received by the user via email is expected to be provided.

func (*Manager) DisableTFA

func (m *Manager) DisableTFA(ctx context.Context, passcode string) error

DisableTFA disables two-factor authentication for the requesting user.

func (*Manager) EnableTFA

func (m *Manager) EnableTFA(ctx context.Context, passcode string) error

EnableTFA enables two-factor authentication for the requesting user. The user must have set it up first (see SetupTFA method).

func (*Manager) GetProfile

func (m *Manager) GetProfile(ctx context.Context) (*hub.User, error)

GetProfile returns the profile of the user doing the request.

func (*Manager) GetProfileJSON

func (m *Manager) GetProfileJSON(ctx context.Context) ([]byte, error)

GetProfileJSON returns the profile of the user doing the request as a json object.

func (*Manager) GetUserID

func (m *Manager) GetUserID(ctx context.Context, email string) (string, error)

GetUserID returns the id of the user with the email provided.

func (*Manager) RegisterDeleteUserCode

func (m *Manager) RegisterDeleteUserCode(ctx context.Context) error

RegisterDeleteUserCode registers a code that allows the user doing the request to initiate the process to delete his account. A link containing the code will be emailed to the user.

func (*Manager) RegisterPasswordResetCode

func (m *Manager) RegisterPasswordResetCode(ctx context.Context, userEmail string) error

RegisterPasswordResetCode registers a code that allows the user identified by the email provided to reset the password. A link containing the code will be emailed to the user to initiate the password reset process.

func (*Manager) RegisterSession

func (m *Manager) RegisterSession(ctx context.Context, session *hub.Session) (*hub.Session, error)

RegisterSession registers a user session in the database.

func (*Manager) RegisterUser

func (m *Manager) RegisterUser(ctx context.Context, user *hub.User) error

RegisterUser registers the user provided in the database. When the user is registered a verification email will be sent to the email address provided. The base url provided will be used to build the url the user will need to click to complete the verification. When a user is registered using oauth, the email is verified automatically and no email is sent.

func (*Manager) ResetPassword

func (m *Manager) ResetPassword(ctx context.Context, code, newPassword string) error

ResetPassword resets the user password in the database.

func (*Manager) SetupTFA

func (m *Manager) SetupTFA(ctx context.Context) ([]byte, error)

SetupTFA sets up two-factor authentication for the requesting user. This generates a new TOTP key and some recovery codes for the user and stores them in the database. To complete the process, the user must enable TFA (see EnableTFA method).

func (*Manager) UpdatePassword

func (m *Manager) UpdatePassword(ctx context.Context, old, new string) error

UpdatePassword updates the user password in the database.

func (*Manager) UpdateProfile

func (m *Manager) UpdateProfile(ctx context.Context, user *hub.User) error

UpdateProfile updates the user profile in the database.

func (*Manager) VerifyEmail

func (m *Manager) VerifyEmail(ctx context.Context, code string) (bool, error)

VerifyEmail verifies a user's email using the email verification code provided.

func (*Manager) VerifyPasswordResetCode

func (m *Manager) VerifyPasswordResetCode(ctx context.Context, code string) error

VerifyPasswordResetCode verifies if the provided code is valid.

type ManagerMock

type ManagerMock struct {
	mock.Mock
}

ManagerMock is a mock implementation of the UserManager interface.

func (*ManagerMock) ApproveSession

func (m *ManagerMock) ApproveSession(ctx context.Context, sessionID, passcode string) error

ApproveSession implements the UserManager interface.

func (*ManagerMock) CheckAvailability

func (m *ManagerMock) CheckAvailability(ctx context.Context, resourceKind, value string) (bool, error)

CheckAvailability implements the UserManager interface.

func (*ManagerMock) CheckCredentials

func (m *ManagerMock) CheckCredentials(
	ctx context.Context,
	email,
	password string,
) (*hub.CheckCredentialsOutput, error)

CheckCredentials implements the UserManager interface.

func (*ManagerMock) CheckSession

func (m *ManagerMock) CheckSession(
	ctx context.Context,
	sessionID string,
	duration time.Duration,
) (*hub.CheckSessionOutput, error)

CheckSession implements the UserManager interface.

func (*ManagerMock) DeleteSession

func (m *ManagerMock) DeleteSession(ctx context.Context, sessionID string) error

DeleteSession implements the UserManager interface.

func (*ManagerMock) DeleteUser

func (m *ManagerMock) DeleteUser(ctx context.Context, code string) error

DeleteUser implements the UserManager interface.

func (*ManagerMock) DisableTFA

func (m *ManagerMock) DisableTFA(ctx context.Context, passcode string) error

DisableTFA implements the UserManager interface.

func (*ManagerMock) EnableTFA

func (m *ManagerMock) EnableTFA(ctx context.Context, passcode string) error

EnableTFA implements the UserManager interface.

func (*ManagerMock) GetProfile

func (m *ManagerMock) GetProfile(ctx context.Context) (*hub.User, error)

GetProfile implements the UserManager interface.

func (*ManagerMock) GetProfileJSON

func (m *ManagerMock) GetProfileJSON(ctx context.Context) ([]byte, error)

GetProfileJSON implements the UserManager interface.

func (*ManagerMock) GetUserID

func (m *ManagerMock) GetUserID(ctx context.Context, email string) (string, error)

GetUserID implements the UserManager interface.

func (*ManagerMock) RegisterDeleteUserCode

func (m *ManagerMock) RegisterDeleteUserCode(ctx context.Context) error

RegisterDeleteUserCode implements the UserManager interface.

func (*ManagerMock) RegisterPasswordResetCode

func (m *ManagerMock) RegisterPasswordResetCode(ctx context.Context, userEmail string) error

RegisterPasswordResetCode implements the UserManager interface.

func (*ManagerMock) RegisterSession

func (m *ManagerMock) RegisterSession(ctx context.Context, session *hub.Session) (*hub.Session, error)

RegisterSession implements the UserManager interface.

func (*ManagerMock) RegisterUser

func (m *ManagerMock) RegisterUser(ctx context.Context, user *hub.User) error

RegisterUser implements the UserManager interface.

func (*ManagerMock) ResetPassword

func (m *ManagerMock) ResetPassword(ctx context.Context, code, newPassword string) error

ResetPassword implements the UserManager interface.

func (*ManagerMock) SetupTFA

func (m *ManagerMock) SetupTFA(ctx context.Context) ([]byte, error)

SetupTFA implements the UserManager interface.

func (*ManagerMock) UpdatePassword

func (m *ManagerMock) UpdatePassword(ctx context.Context, old, new string) error

UpdatePassword implements the UserManager interface.

func (*ManagerMock) UpdateProfile

func (m *ManagerMock) UpdateProfile(ctx context.Context, user *hub.User) error

UpdateProfile implements the UserManager interface.

func (*ManagerMock) VerifyEmail

func (m *ManagerMock) VerifyEmail(ctx context.Context, code string) (bool, error)

VerifyEmail implements the UserManager interface.

func (*ManagerMock) VerifyPasswordResetCode

func (m *ManagerMock) VerifyPasswordResetCode(ctx context.Context, code string) error

VerifyPasswordResetCode implements the UserManager interface.

Jump to

Keyboard shortcuts

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