Documentation ¶
Index ¶
- Variables
- type MockService
- type MySQLService
- type Service
- type User
- func (u *User) Activate(activationToken string) (bool, error)
- func (u *User) ChangePassword(password string) error
- func (u *User) ChangePasswordFromForget(forgetPasswordToken, password string) error
- func (u *User) ForgetPassword() (string, error)
- func (u *User) ReactivateToken() (string, error)
- func (u *User) SignIn(email, password string) error
- func (u User) Validate() error
Constants ¶
This section is empty.
Variables ¶
var ErrActivationTokenInvalid = errors.New("Activation Token is invalid")
var ErrAddressLong = errors.New("Address cannot be longer than 120 characters")
var ErrEmailInvalid = errors.New("Email is invalid")
var ErrForgetPasswordTokenInvalid = errors.New("Forget Password Token is invalid")
var ErrLogin = errors.New("Email or password provided does not match")
var ErrNameLong = errors.New("Name cannot be longer than 120 characters")
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
var ErrPasswordInvalid = errors.New("Password requires at least 1 capital letter, 1 small letter and a number")
var ErrPasswordLong = errors.New("Password cannot be longer than 120 characters")
var ErrPasswordShort = errors.New("Password cannot be shorter than 8 characters")
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) GetByEmail ¶
func (u MockService) GetByEmail(Email string) (User, error)
type MySQLService ¶
func (MySQLService) GetByEmail ¶
func (s MySQLService) GetByEmail(a string) (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 ¶
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 ¶
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 ¶
ChangePassword changes the password on the user object before saving it
func (*User) ChangePasswordFromForget ¶
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 ¶
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 ¶
ReactivateToken resets the activation token in the case the user did not activate the account in time. Returns an activationToken