user

package
v0.0.0-...-b1989ba Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ActiveUserSessionMap = make(map[LoginReq]time.Time)
	UserSessionMapMutex  = &sync.RWMutex{}
)

Functions

func CheckIfValidUser

func CheckIfValidUser(db *gorm.DB, loginDetails LoginReq) error

CheckIfValidUser ...

func Hash

func Hash(password string) ([]byte, error)

Hash - to encrypt user's password.

func VerifyPassword

func VerifyPassword(hashedPassword, password string) error

VerifyPassword - compare hashed password and given password.

Types

type LoginReq

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

LoginReq ...

type User

type User struct {
	Role      string    `gorm:"default:user" json:"role"`
	ID        uint32    `gorm:"primary_key;auto_increment" json:"id"`
	FirstName string    `gorm:"size:255;not null" json:"first_name"`
	LastName  string    `gorm:"size:255;not null" json:"last_name"`
	Email     string    `gorm:"size:100;not null;unique" json:"email"`
	Phone     int64     `gorm:"size:100;unique;not null" json:"phone"`
	Password  string    `gorm:"size:100;not null;" json:"password"`
	Address   string    `gorm:"size:255" json:"address"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP" json:"updated_at"`
}

User ...

func (*User) AfterCreate

func (u *User) AfterCreate(tx *gorm.DB) (err error)

func (*User) BeforeSave

func (u *User) BeforeSave(tx *gorm.DB) error

BeforeSave ...

func (*User) CreateUser

func (u *User) CreateUser(db *gorm.DB) (*User, error)

CreateUser - add new user to DB table.

func (*User) Prepare

func (u *User) Prepare()

Prepare ...

func (*User) Validate

func (u *User) Validate(action string) error

Validate ...

Jump to

Keyboard shortcuts

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