user

package
v0.0.0-...-e6b7f3d Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidUser            = errors.New("invalid user")
	ErrEmailAlreadyExists     = errors.New("email already exists")
	ErrInvalidCurrentPassword = errors.New("your current password is not valid")
	ErrUnchangedEmail         = errors.New("your new email is the same with your current email")
	ErrEmailAlreadyConfirmed  = errors.New("your email is already confirmed")
)
View Source
var Table = "users"

Functions

func ConfirmEmail

func ConfirmEmail(ctx context.Context, dbConn *gorm.DB, token string) error

ConfirmEmail operates as controller to confirm a user's email

func ConfirmEmailResend

func ConfirmEmailResend(ctx context.Context, dbConn *gorm.DB, id string, emailService email.Email) error

ConfirmEmailResend operates as controller to send a confirm email

func Login

func Login(ctx context.Context, dbConn *gorm.DB, authService auth.Auth, loginUser *LoginUser) (string, error)

Login operates as controller to login a user

func ResetPassword

func ResetPassword(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPassword, token string) error

ResetPassword operates as controller to reset user's password

func ResetPasswordEmail

func ResetPasswordEmail(ctx context.Context, dbConn *gorm.DB, resetUser *ResetUserPasswordEmail, emailService email.Email) error

ResetPasswordEmail operates as controller to send email for password reset

func UpdatePassword

func UpdatePassword(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserPassword, userID string) error

UpdatePassword operates as controller to update existing user password

Types

type LoginUser

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

LoginUser contains the schema for user login

type NewUser

type NewUser struct {
	FirstName    string    `json:"first_name"`
	LastName     string    `json:"last_name"`
	Email        string    `json:"email"`
	Password     string    `json:"password"`
	Country      string    `json:"country"`
	MobilePhone  string    `json:"mobile_phone"`
	Role         string    `json:"-"`
	ConfirmToken string    `json:"-"`
	IsConfirmed  bool      `json:"-"`
	CreatedAt    time.Time `json:"-"`
	UpdatedAt    time.Time `json:"-"`
}

NewUser contains the schema to create new identity

type ResetUserPassword

type ResetUserPassword struct {
	Password  string    `json:"password"`
	UpdatedAt time.Time `json:"-"`
}

ResetUserPassword contains the schema to reset user password

type ResetUserPasswordEmail

type ResetUserPasswordEmail struct {
	Email      string    `json:"email"`
	ResetToken string    `json:"-"`
	UpdatedAt  time.Time `json:"-"`
}

ResetUserPasswordEmail contains the schema to send email for reset user password

type Statistics

type Statistics struct {
	Total      int            `json:"total"`
	LastWeek   int            `json:"last_week"`
	LastMonth  int            `json:"last_month"`
	PerCountry map[string]int `json:"per_country"`
}

Metrics contains the schema for users metrics

func ReadStatistics

func ReadStatistics(ctx context.Context, dbConn *gorm.DB) (*Statistics, error)

ReadStatistics operates as controller to calculate statistics for users

type UpdateUserEmail

type UpdateUserEmail struct {
	Email           string    `json:"email"`
	ConfirmToken    string    `json:"-"`
	IsConfirmed     bool      `json:"-"`
	UpdatedAt       time.Time `json:"-"`
	CurrentPassword string    `json:"current_password" gorm:"-"`
}

UpdateUserEmail contains the schema to update user email

type UpdateUserInfo

type UpdateUserInfo struct {
	FirstName       string    `json:"first_name"`
	LastName        string    `json:"last_name"`
	Country         string    `json:"country"`
	MobilePhone     string    `json:"mobile_phone"`
	UpdatedAt       time.Time `json:"-"`
	CurrentPassword string    `json:"current_password" gorm:"-"`
}

UpdateUserInfo contains the schema to update user info

type UpdateUserPassword

type UpdateUserPassword struct {
	Password        string    `json:"password"`
	UpdatedAt       time.Time `json:"-"`
	CurrentPassword string    `json:"current_password" gorm:"-"`
}

UpdateUserPassword contains the schema to update user password

type User

type User struct {
	ID           int       `json:"id" gorm:"primary_key;unique;not null"`
	FirstName    string    `json:"first_name" gorm:"not null"`
	LastName     string    `json:"last_name" gorm:"not null"`
	Email        string    `json:"email" gorm:"not null"`
	Password     string    `json:"-" gorm:"not null"`
	Country      string    `json:"country" gorm:"not null"`
	MobilePhone  string    `json:"mobile_phone" gorm:"not null"`
	Role         string    `json:"role" gorm:"default:User;not null"`
	ConfirmToken string    `json:"-" gorm:"not null"`
	ResetToken   string    `json:"-" gorm:"default:null"`
	IsConfirmed  bool      `json:"is_confirmed" gorm:"default:false;not null"`
	CreatedAt    time.Time `json:"created_at" gorm:"default:CURRENT_TIMESTAMP;not null"`
	UpdatedAt    time.Time `json:"updated_at" gorm:"default:CURRENT_TIMESTAMP;not null"`
}

User contains the schema for specific identity

func Create

func Create(ctx context.Context, dbConn *gorm.DB, newUser *NewUser, emailService email.Email) (*User, error)

Create operates as controller to create a new user

func Read

func Read(ctx context.Context, dbConn *gorm.DB) ([]*User, error)

Read operates as controller to list users

func ReadID

func ReadID(ctx context.Context, dbConn *gorm.DB, id string) (*User, error)

ReadID operates as controller to retrieve a user by ID

func UpdateEmail

func UpdateEmail(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserEmail, userID string, emailService email.Email) (*User, error)

UpdateEmail operates as controller to update existing user email

func UpdateInfo

func UpdateInfo(ctx context.Context, dbConn *gorm.DB, updateUser *UpdateUserInfo, userID string) (*User, error)

UpdateInfo operates as controller to update existing user info

Jump to

Keyboard shortcuts

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