users

package
v0.0.0-...-f2300c2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrActivationTokenInvalid = errors.New("Activation Token is invalid")
View Source
var ErrAddressLong = errors.New("Address cannot be longer than 120 characters")
View Source
var ErrEmailInvalid = errors.New("Email is invalid")
View Source
var ErrForgetPasswordTokenInvalid = errors.New("Forget Password Token is invalid")
View Source
var ErrLogin = errors.New("Email or password provided does not match")
View Source
var ErrNameLong = errors.New("Name cannot be longer than 120 characters")
View Source
var ErrNameShort = errors.New("Name cannot be shorter than 4 characters")

ErrNameShort is an error that is to be raised if First Name or Last Name provided is too short

View Source
var ErrPasswordInvalid = errors.New("Password requires at least 1 capital letter, 1 small letter and a number")
View Source
var ErrPasswordLong = errors.New("Password cannot be longer than 120 characters")
View Source
var ErrPasswordShort = errors.New("Password cannot be shorter than 8 characters")
View Source
var ErrSamePassword = errors.New("Current password already in use. Please pick another password")

Functions

This section is empty.

Types

type MockService

type MockService struct{}

func (MockService) Create

func (u MockService) Create(*User) (User, error)

func (MockService) GetByEmail

func (u MockService) GetByEmail(Email string) (User, error)

func (MockService) GetByID

func (u MockService) GetByID(ID string) (User, error)

func (MockService) Update

func (u MockService) Update(*User) (User, error)

type MySQLService

type MySQLService struct {
	DB *gorm.DB
}

func (MySQLService) Create

func (s MySQLService) Create(a *User) (User, error)

func (MySQLService) GetByEmail

func (s MySQLService) GetByEmail(a string) (User, error)

func (MySQLService) GetByID

func (s MySQLService) GetByID(ID string) (User, error)

func (MySQLService) Update

func (s MySQLService) Update(a *User) (User, error)

type Service

type Service interface {
	GetByID(ID string) (User, error)
	GetByEmail(Email string) (User, error)
	Create(*User) (User, error)
	Update(*User) (User, error)
}

Service interfaces defines the list of methods that the service needs to provide for the user handlers

type User

type User struct {
	ID                       string    `json:"id"`
	FirstName                string    `json:"first_name"`
	LastName                 string    `json:"last_name"`
	Email                    string    `json:"email"`
	Address                  string    `json:"address"`
	Password                 string    `json:"-"`
	ForgetPasswordToken      string    `json:"-"`
	ForgetPasswordExpiryDate time.Time `json:"-"`
	ActivationToken          string    `json:"-"`
	ActivationExpiryDate     time.Time `json:"-"`
	Activated                bool      `json:"-"`
	LastLoginAt              time.Time `json:"-"`
	CreatedAt                time.Time `json:"-"`
	UpdatedAt                time.Time `json:"-"`
}

User struct defines the user entity in the application Fields need to be set as public in order for other packages to access them

func NewUser

func NewUser(firstName, lastName, email, password string) (*User, error)

NewUser returns a new user instance. During instantiation, several fields will need to be instantiated; e.g. ID, Activated, CreatedAt, UpdatedAt, etc The function would be able to return its own set of errors as it would run a validate function before returning a reference of the user back

func (*User) Activate

func (u *User) Activate(activationToken string) (bool, error)

Activate user. You would need to provide a activation token to check if it correct. If correct, it would return the status of the user which should be true or false

func (*User) ChangePassword

func (u *User) ChangePassword(password string) error

ChangePassword changes the password on the user object before saving it

func (*User) ChangePasswordFromForget

func (u *User) ChangePasswordFromForget(forgetPasswordToken, password string) error

ChangePasswordFromForget requires you to provide the forget password token. This function will then check the forgetPasswordToken if its correct and alters it accordingly

func (*User) ForgetPassword

func (u *User) ForgetPassword() (string, error)

ForgetPassword resets the forget password token to a random UUID as well as resets the forget password expiry token. The function will return the forgetPasswordToken

func (*User) ReactivateToken

func (u *User) ReactivateToken() (string, error)

ReactivateToken resets the activation token in the case the user did not activate the account in time. Returns an activationToken

func (*User) SignIn

func (u *User) SignIn(email, password string) error

SignIn requires both email and password to be passed in and to be checked that they are correct before the system would allow access. At the same time, the user model would have its lastloginat field updated to the latest timing

func (User) Validate

func (u User) Validate() error

Validate checks all entries are correct before passing itself to a service to be saved

Jump to

Keyboard shortcuts

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