model

package
v0.0.0-...-a03fb21 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password string, hash string) bool

func CleanUpSessions

func CleanUpSessions() (err error)

func HashPassword

func HashPassword(password string) (hash string, err error)

Types

type Session

type Session struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	Uuid      string    `gorm:"not null;unique" json:"uuid"` // Set field as not nullable and unique
	UserID    uint      `gorm:"index" valid:"required"`
	ExpiresAt time.Time `json:"expiresAt" valid:"required"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
}

func (*Session) BeforeCreate

func (s *Session) BeforeCreate() (err error)

func (Session) Validate

func (s Session) Validate(db *gorm.DB)

type User

type User struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	Uuid      string    `gorm:"not null;unique" json:"uuid"` // Set field as not nullable and unique
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`
	FirstName string    `gorm:"size:255" valid:"optional" json:"firstName"`          // Default size for string is 255, reset it with this tag
	LastName  string    `gorm:"size:255" valid:"optional" json:"lastName"`           // Default size for string is 255, reset it with this tag
	Email     string    `gorm:"not null;unique" valid:"required,email" json:"email"` // Set field as not nullable and unique
	Password  string    `gorm:"size:255" json:"password"`
	Sessions  []Session `json:"sessions"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate() (err error)

GORM callback: Encode password before create

func (*User) BeforeUpdate

func (u *User) BeforeUpdate() (err error)

Detect if password was set, encode it if needed

func (User) Validate

func (u User) Validate(db *gorm.DB)

Jump to

Keyboard shortcuts

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