user

package
v0.0.0-...-51ef577 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

package user holds user domain logic

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmailInvalid is when given email is not a valid email.
	ErrEmailInvalid = apperror.NewBadRequest("email is not a valid email")
	// ErrPasswordInvalid is when given password is not a valid password.
	ErrPasswordInvalid = apperror.NewBadRequest("password is not a valid password")
)

Functions

This section is empty.

Types

type EmailAddress

type EmailAddress string

EmailAddress is an email address.

func (EmailAddress) IsValid

func (e EmailAddress) IsValid() *apperror.AppError

IsValid returns error if string is not valid email.

type Password

type Password string

Password is an email address.

func (Password) ComparePassword

func (h Password) ComparePassword(pwd string) bool

ComparePassword verifies if password matched with hash

func (*Password) HashAndSalt

func (p *Password) HashAndSalt(cost int) *apperror.AppError

HashAndSalt hash and salt the password

func (Password) IsValid

func (p Password) IsValid() *apperror.AppError

IsValid returns error if string is not valid password.

func (Password) String

func (p Password) String() string

type Repository

type Repository interface {
	NewId() string
	InsertOne(ctx context.Context, u *User) *apperror.AppError
	UpdateOne(ctx context.Context, u *User) *apperror.AppError
	FindOne(ctx context.Context, id string) (*User, *apperror.AppError)
	FindByEmail(ctx context.Context, email EmailAddress) (*User, *apperror.AppError)
}

Repository allows persistent operations for User

type User

type User struct {
	ID        string       `json:"id,omitempty" bson:"_id,omitempty"`
	Email     EmailAddress `json:"email,omitempty" bson:"email"`
	Hash      Password     `json:"hash,omitempty" bson:"hash"`
	CreatedAt time.Time    `json:"createdAt,omitempty" bson:"createdAt,omitempty"`
	UpdatedAt time.Time    `json:"updatedAt,omitempty" bson:"updatedAt,omitempty"`
}

User aggregate root

func New

func New(id string, email EmailAddress) User

New creates an User

func (*User) Register

func (u *User) Register(pwd Password) *apperror.AppError

Register set current user email and hash+salt password

Jump to

Keyboard shortcuts

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