user

package module
v0.0.0-...-b45dc3e Latest Latest
Warning

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

Go to latest
Published: May 20, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const ActivationPageLink string = "http://localhost:5173/activate?token="

Variables

View Source
var (
	ErrInvalidJWT          = errors.New("invalid jwt")
	ErrInvalidJWTSignature = errors.New("invalid jwt signature")
)
View Source
var ErrDuplicateUser = errors.New("user already exists")
View Source
var ErrInvalidEmail = errors.New("user with this email was not found")
View Source
var ErrInvalidPassword = errors.New("invalid password provided")
View Source
var ErrMissingEnvs = errors.New("service: missing environment variables")

used by helper functions in service

View Source
var ErrMissingField = errors.New("missing field is required")
View Source
var ErrUserNotActivated = errors.New("user has not activated their account")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func NewGRPCMailerClient

func NewGRPCMailerClient(port string) (*grpcMailerClient, error)

func NewHTTPHandler

func NewHTTPHandler(service Service) http.Handler

func NewHTTPMailerClient

func NewHTTPMailerClient(mailerEndpoint string) (*httpMailerClient, error)

func NewMongoClient

func NewMongoClient(uri string, timeout int) (*mongo.Client, error)

func NewServer

func NewServer(handler http.Handler, port string) *server

func NewValidator

func NewValidator() *validator

Types

type MailerClient

type MailerClient interface {
	// contains filtered or unexported methods
}

MailerClient is used by Service to make http or grpc calls to other services

type PasswordManager

type PasswordManager interface {
	GenerateHash(password string) (string, error)
	CompareHashWith(hashedPassword, password string) error
}

func NewPasswordManager

func NewPasswordManager(cost int) PasswordManager

type Repository

type Repository interface {
	// contains filtered or unexported methods
}

! I'm not sure where to convert a UserInfo type to a UserDocument type ! in the repository or service layer

func NewRepository

func NewRepository(client *mongo.Client, database string) Repository

Create a new user repository with the mongo client and database name

type Service

type Service interface {
	// contains filtered or unexported methods
}

func NewService

func NewService(repository Repository, opts ...ServiceOption) Service

type ServiceBuilder

type ServiceBuilder interface {
	Repository(repository Repository) ServiceBuilder
	MailerClient(client MailerClient) ServiceBuilder
	TokenClient(token TokenClient) ServiceBuilder
	PasswordManager(passwordManager PasswordManager) ServiceBuilder
	Validator(validator Validator) ServiceBuilder
	Build() Service
}

! ServiceBuilder may be deprecated in favour of the ! idiomatic functional options pattern. I'm going to ! keep this here until I refactor some of the tests. ! I also want to see how it stacks up to the fo pattern ! when I do more benchmarking and profiling.

func NewServiceBuilder

func NewServiceBuilder() ServiceBuilder

type ServiceOption

type ServiceOption func(s *service)

func WithMailerClient

func WithMailerClient(m MailerClient) ServiceOption

func WithPasswordManager

func WithPasswordManager(p PasswordManager) ServiceOption

func WithTokenClient

func WithTokenClient(t TokenClient) ServiceOption

func WithValidator

func WithValidator(v Validator) ServiceOption

type TokenClient

type TokenClient interface {
	CreateActivationToken(ctx context.Context, userID string) (string, error)
	ValidateActivationToken(ctx context.Context, activationToken string) (string, error)
}

func NewTokenClient

func NewTokenClient(port string) (TokenClient, error)

type UserClaims

type UserClaims struct {
	jwt.MapClaims
	UserID string
}

type UserDocument

type UserDocument struct {
	OID            primitive.ObjectID `bson:"_id,omitempty"`
	FirstName      string             `bson:"firstName"`
	LastName       string             `bson:"lastName"`
	Email          string             `bson:"email"`
	HashedPassword string             `bson:"hashedPassword"`
	Activated      bool               `bson:"activated"`
	CreatedAt      *time.Time         `bson:"createdAt"`
	UpdatedAt      *time.Time         `bson:"updatedAt"`
}

UserDocument is used to be used by a mongo repository implementation to transfer user data

type UserInfo

type UserInfo struct {
	ID             string     `json:"id"`
	FirstName      string     `json:"firstName"`
	LastName       string     `json:"lastName"`
	Email          string     `json:"email"`
	Password       string     `json:"-"`
	HashedPassword string     `json:"-"`
	Activated      bool       `json:"-"`
	CreatedAt      *time.Time `json:"-"`
	UpdatedAt      *time.Time `json:"-"`
	Token          string     `json:"token"`
}

UserInfo is sent out as a response

type UserLoginInfo

type UserLoginInfo struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

UserLoginInfo stores request data for logging in a user

type UserRegistrationDocument

type UserRegistrationDocument struct {
	FirstName      string     `bson:"firstName"`
	LastName       string     `bson:"lastName"`
	Email          string     `bson:"email"`
	HashedPassword string     `bson:"hashedPassword"`
	Activated      bool       `bson:"activated"`
	CreatedAt      *time.Time `bson:"createdAt"`
	UpdatedAt      *time.Time `bson:"updatedAt"`
}

type UserRegistrationInfo

type UserRegistrationInfo struct {
	FirstName      string     `json:"firstName"`
	LastName       string     `json:"lastName"`
	Email          string     `json:"email"`
	Password       string     `json:"password"`
	HashedPassword string     `json:"-"`
	Activated      bool       `json:"activated"`
	CreatedAt      *time.Time `json:"createdAt"`
	UpdatedAt      *time.Time `json:"updatedAt"`
}

UserRegistrationInfo stores request data for registering a new user

type Validator

type Validator interface {
	Registration(u UserRegistrationInfo) error
	Login(u UserLoginInfo) error
	NonEmptyString(name, field string) error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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