users

package
v0.0.0-...-96c172f Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NotifRequestRegistration  string = "users_requestregistration"
	NotifRequestPasswordReset string = "users_requestpasswordreset"
)

Notification template names

View Source
const (
	ErrUserExists = consterr.ConstErr("ErrUserExists")
	ErrNotFound   = consterr.ConstErr("ErrNotFound")
	ErrConsumed   = consterr.ConstErr("ErrConsumed")
	ErrExpired    = consterr.ConstErr("ErrExpired")

	ErrNotificationFailed = consterr.ConstErr("ErrNotificationFailed")
)

Error definitions for the user registration, login and reset password flows.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmailRegistration

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

EmailRegistration is the controller to handle an email registration flow

func NewEmailRegistration

func NewEmailRegistration(
	ins *obs.Insighter,
	composer notifications.Composer,
	mailSender mailer.Mailer,
	regRepo RegistrationRepo,
	hostInfo HostInfo) *EmailRegistration

NewEmailRegistration creates a new EmailRegistration controller

func (*EmailRegistration) Activate

func (r *EmailRegistration) Activate(token string) error

Activate completes the activation of a registered user.

func (*EmailRegistration) GetUser

func (r *EmailRegistration) GetUser(userID ids.ID) (*User, error)

GetUser returns a user given its ID

func (*EmailRegistration) Login

func (r *EmailRegistration) Login(email string, password string) (ids.ID, error)

Login check if a user email and password are correct.

func (*EmailRegistration) Register

func (r *EmailRegistration) Register(email string, password string) error

Register creates an inactive user, and send a notification (email), with the activation link.

func (*EmailRegistration) RequestResetPassword

func (r *EmailRegistration) RequestResetPassword(email string) error

RequestResetPassword creates a temporal reset token and sends it to the user email, so it can reset the password.

func (*EmailRegistration) ResetPasswordWithToken

func (r *EmailRegistration) ResetPasswordWithToken(token string, newPassword string) error

ResetPasswordWithToken sets a new password for a given user using a reset password token

type HostInfo

type HostInfo struct {
	Scheme            string // http or https
	Host              string // includes port
	ActivationPath    string // activation path where the handler has been installed
	ResetPasswordPath string // reset pass path where the handler has been installed
}

HostInfo contains the required info to construct a URL to where a user can be redirected to use an activation token, or use a reset password token. This information might not be available if the request is proxied, so it can be configured at startup time.

type NopRegistrationRepo

type NopRegistrationRepo struct {
}

NopRegistrationRepo is an empty not working implementation of a RegistrationRepo

func (*NopRegistrationRepo) ActivateUser

func (r *NopRegistrationRepo) ActivateUser(token string) (*User, error)

ActivateUser confirms an user email with its activation token.

func (*NopRegistrationRepo) CheckPassword

func (r *NopRegistrationRepo) CheckPassword(email string, password string) (ids.ID, error)

CheckPassword return the user ID for a user from its email and password.

func (*NopRegistrationRepo) CreateInactiveUser

func (r *NopRegistrationRepo) CreateInactiveUser(
	email string, password string) (string, error)

CreateInactiveUser return a token for the user to be used to confirm the account.

func (*NopRegistrationRepo) CreatePasswordResetRequest

func (r *NopRegistrationRepo) CreatePasswordResetRequest(email string) (*User, string, error)

CreatePasswordResetRequest returns a token for password reset.

func (*NopRegistrationRepo) DeleteUser

func (r *NopRegistrationRepo) DeleteUser(email string) error

DeleteUser deletes an existing user

func (*NopRegistrationRepo) GetUserByEmail

func (r *NopRegistrationRepo) GetUserByEmail(email string) *User

GetUserByEmail returns the User for a given email, or nil if the email is not found in the data repo.

func (*NopRegistrationRepo) GetUserByID

func (r *NopRegistrationRepo) GetUserByID(userID ids.ID) *User

GetUserByID returns a User for a given ID, or nil if there is no user for that ID.

func (*NopRegistrationRepo) ListUsers

func (r *NopRegistrationRepo) ListUsers(from ids.ID, limit int, backwards bool) ([]User, error)

ListUsers lists users with pagination

func (*NopRegistrationRepo) ResetPassword

func (r *NopRegistrationRepo) ResetPassword(token string, password string) (*User, error)

ResetPassword changes the pasword for the user associated with the given reset password token

type RegistrationRepo

type RegistrationRepo interface {

	// GetUserByEmail returns the User for a given email,
	// or nil if the email is not found in the data repo.
	GetUserByEmail(email string) *User

	// GetUserByID returns a User for a given ID, or nil
	// if there is no user for that ID.
	GetUserByID(userID ids.ID) *User

	// CreateInactiveUser return a token for the user to be used
	// to confirm the account.
	CreateInactiveUser(email string, password string) (string, error)

	// ActivateUser confirms an user email with its activation token.
	ActivateUser(token string) (*User, error)

	// CreatePasswordResetRequest returns a token for password reset.
	CreatePasswordResetRequest(email string) (*User, string, error)

	// ResetPassword changes the pasword for the user associated with
	// the given reset password token
	ResetPassword(token string, password string) (*User, error)

	// CheckPassword return the user ID for a user from its email
	// and password.
	CheckPassword(email string, password string) (ids.ID, error)

	// DeleteUser deletes a created user
	DeleteUser(email string) error

	// ListUsers lists users with pagination
	ListUsers(from ids.ID, limit int, backwards bool) ([]User, error)
}

RegistrationRepo defines the data access interface to implement an Email user registration (and reset password) workflow.

type RepoSQLX

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

RepoSQLX implemnte the RegistrationRepo interface with a SQL db.

func NewRepoSQLX

func NewRepoSQLX(ins *obs.Insighter, sqlDB db.SQLDB,
	tokenSalt string) *RepoSQLX

NewRepoSQLX creates a new RepoSQLX

func (*RepoSQLX) ActivateUser

func (r *RepoSQLX) ActivateUser(token string) (*User, error)

ActivateUser confirms an user email with its activation token.

func (*RepoSQLX) CheckPassword

func (r *RepoSQLX) CheckPassword(email string, password string) (ids.ID, error)

CheckPassword return the user ID for a user from its email and password.

func (*RepoSQLX) CreateInactiveUser

func (r *RepoSQLX) CreateInactiveUser(
	email string, password string) (string, error)

CreateInactiveUser return a token for the user to be used to confirm the account.

func (*RepoSQLX) CreatePasswordResetRequest

func (r *RepoSQLX) CreatePasswordResetRequest(email string) (*User, string, error)

CreatePasswordResetRequest returns a token for password reset.

func (*RepoSQLX) DeleteUser

func (r *RepoSQLX) DeleteUser(email string) error

DeleteUser hard deletes a user (and all its related data will be deleted too)

func (*RepoSQLX) GetUserByEmail

func (r *RepoSQLX) GetUserByEmail(email string) *User

GetUserByEmail returns the User for a given email, or nil if the email is not found in the data repo.

func (*RepoSQLX) GetUserByID

func (r *RepoSQLX) GetUserByID(userID ids.ID) *User

GetUserByID returns a User for a given ID, or nil if there is no user for that ID.

func (*RepoSQLX) ListUsers

func (r *RepoSQLX) ListUsers(from ids.ID, limit int, backwards bool) ([]User, error)

ListUsers lists users with pagination

func (*RepoSQLX) ResetPassword

func (r *RepoSQLX) ResetPassword(token string, password string) (*User, error)

ResetPassword changes the pasword for the user associated with the given reset password token

type User

type User struct {
	ID      ids.ID
	Email   string
	Created time.Time
}

User represents a user in the system

func (*User) String

func (u *User) String() string

Jump to

Keyboard shortcuts

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