user

package
v0.0.0-...-9d742bf Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package user groups together user authentication code. Authenticating the user, signing in, retrieving signed-in current user, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFirstTimeRegistrationGetHandler

func NewFirstTimeRegistrationGetHandler(
	te adapter.TemplateExecutor,
	ar adapter.AssetsResolver,
) http.Handler

NewFirstTimeRegistrationGetHandler creates a new handler for GET /first-time-registration

func NewFirstTimeRegistrationPostHandler

func NewFirstTimeRegistrationPostHandler(
	us Store,
	de *schema.Decoder,
) http.Handler

NewFirstTimeRegistrationPostHandler creates a new handler for POST /first-time-registration

func NewSignInGetHandler

func NewSignInGetHandler(
	te adapter.TemplateExecutor,
	ar adapter.AssetsResolver,
) http.Handler

NewSignInGetHandler creates a new handler for GET /sign-in

func NewSignInPostHandler

func NewSignInPostHandler(
	userStore Store,
	sessionManager *sessionup.Manager,
	decoder *schema.Decoder,
) http.Handler

NewSignInPostHandler creates a new handler for POST /sign-in

func NewSignOutPostHandler

func NewSignOutPostHandler(
	sessionManager *sessionup.Manager,
) http.Handler

NewSignOutPostHandler creates a new handler for POST /sign-out

func Register

func Register(
	router *mux.Router,
	templateExecutor adapter.TemplateExecutor,
	assetsResolver adapter.AssetsResolver,
	userStore Store,
	sessionManager *sessionup.Manager,
	decoder *schema.Decoder,
)

Register registers the routes on the given gorilla/mux router.

Types

type Current

type Current struct {
	ID       uint
	Email    string
	Username string
}

Current represents the currently signed-in user authentified by its session.

type DAO

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

DAO implements Store

func (*DAO) GetUserMatchingEmail

func (d *DAO) GetUserMatchingEmail(ctx context.Context, email string) (*PossibleMatch, error)

GetUserMatchingEmail retrieves the user matching the provided email address. If the email is found, it will return a PossibleMatch. If it isn't found, it will return an error.

func (*DAO) GetUserMatchingSession

func (d *DAO) GetUserMatchingSession(ctx context.Context) (*Current, error)

GetUserMatchingSession retrieves the current user from the current session attached to the request context.

func (*DAO) SaveFirstAdministrator

func (d *DAO) SaveFirstAdministrator(ctx context.Context, registration *Registration) error

SaveFirstAdministrator creates the first administrator account whose credentials are given in the registration.

type PossibleMatch

type PossibleMatch struct {
	ID           uint
	Email        string
	PasswordHash []byte
}

PossibleMatch represents a user with the same email credential as the one provided in the sign-in form. It still needs to check the password matches.

type Registration

type Registration struct {
	Email        string
	PasswordHash []byte
	Username     string
}

Registration represents the data needed to save the user in databse. Instead of a password, it needs a password hash.

type RegistrationForm

type RegistrationForm struct {
	Email    string `schema:"email,required"`
	Password string `schema:"password,required"`
	Username string `schema:"username,required"`
}

RegistrationForm represents the registration information provided by users to create their account

type SignInForm

type SignInForm struct {
	Email    string `schema:"email,required"`
	Password string `schema:"password,required"`
}

SignInForm represents the credentials provided by users to sign in

type Store

type Store interface {
	GetUserMatchingEmail(ctx context.Context, email string) (*PossibleMatch, error)
	GetUserMatchingSession(ctx context.Context) (*Current, error)
	SaveFirstAdministrator(ctx context.Context, registration *Registration) error
}

Store handles database operations related to Users

func NewDAO

func NewDAO(db *sql.DB) Store

NewDAO creates a new DAO

Jump to

Keyboard shortcuts

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