usergrp

package
v0.0.0-...-c2300e3 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package usergrp maintains the group of handlers for user access.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidID     = errors.New("id is not in its proper form")
	ErrInvalidStatus = errors.New("status is not allowed for this action")
	ErrInvalidOTP    = errors.New("otp is invalid")
)

Set of error variables for handling product group errors.

Functions

This section is empty.

Types

type AppRegister

type AppRegister struct {
	FirstName string `json:"firstName" validate:"required"`
	LastName  string `json:"lastName"`
	Phone     string `json:"phone" validate:"required,number,startswith=0,len=10"`
	Password  string `json:"password" validate:"required,min=6"`
}

AppRegister contains information needed for a new user to register.

func (AppRegister) Validate

func (r AppRegister) Validate() error

Validate checks the data in the model is considered clean.

type AppUpdateUser

type AppUpdateUser struct {
	FirstName *string `json:"firstName"`
	LastName  *string `json:"lastName"`
	Password  *string `json:"password" validate:"omitempty,min=6"`
}

func (AppUpdateUser) Validate

func (r AppUpdateUser) Validate() error

Validate checks the data in the model is considered clean.

type AppUser

type AppUser struct {
	ID           string   `json:"id"`
	FirstName    string   `json:"firstName"`
	LastName     string   `json:"lastName"`
	Phone        string   `json:"phone"`
	Roles        []string `json:"roles"`
	PasswordHash []byte   `json:"-"`
	Status       string   `json:"status"`
	CreatedAt    string   `json:"CreatedAt"`
	UpdatedAt    string   `json:"UpdatedAt"`
}

AppUser represents information about an individual user.

type AppVerifyOTP

type AppVerifyOTP struct {
	UserID string `json:"user_id" validate:"required,uuid"`
	OTP    string `json:"otp" validate:"required,len=6"`
}

func (AppVerifyOTP) Validate

func (r AppVerifyOTP) Validate() error

Validate checks the data in the model is considered clean.

type Handlers

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

Handlers manages the set of user endpoints.

func New

func New(
	user *user.Core,
	auth *auth.Auth,
	keyID string,
	sms *sms.SMS,
) *Handlers

New constructs a handlers for route access.

func (*Handlers) Register

func (h *Handlers) Register(ctx context.Context, w http.ResponseWriter, r *http.Request) error

Register adds a new user to the system. TODO: limit the number of user can be created (use reCAPTCHA v3, limit by ip, device id)

func (*Handlers) Token

Token provides an API token for the authenticated user.

func (*Handlers) Update

func (h *Handlers) Update(ctx context.Context, w http.ResponseWriter, r *http.Request) error

func (*Handlers) VerifyOTP

func (h *Handlers) VerifyOTP(ctx context.Context, w http.ResponseWriter, r *http.Request) error

VerifyOTP verify user OTP.

Jump to

Keyboard shortcuts

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