model

package
v0.0.0-...-5377c57 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDBElementsExists

func EnsureDBElementsExists(db *sql.DB, config *config.DB, logger *log.Logger) error

EnsureDBElementsExists ensure that required tables/roles/schemas, exists on the database

Types

type User

type User struct {
	ID                 string `json:"id"`
	Email              string `json:"email"`
	Password           string `json:"password"`
	Confirmed          bool
	ConfirmToken       sql.NullString
	ResetPasswordToken sql.NullString
}

User represents a user of our auth system

func (*User) CheckEmailDomain

func (u *User) CheckEmailDomain(domains []string) bool

CheckEmailDomain checks if the user's email address matches the provied domains list

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

CheckPassword checks if the provided password matches the actual user's password hash

func (*User) Create

func (u *User) Create(db *sql.DB) error

Create allow us to create new user in database

func (*User) CreateJWTToken

func (u *User) CreateJWTToken(role, secret string, exp int) (string, error)

CreateJWTToken creates a new JWT token for the user

func (*User) CreateRandomPassword

func (u *User) CreateRandomPassword(length int) error

GeneratePassword generate random password

func (*User) CreateResetToken

func (u *User) CreateResetToken(db *sql.DB, secret string) error

CreateResetToken create a random reset token

func (*User) FindByEmail

func (u *User) FindByEmail(db *sql.DB) error

FindByEmail allows us to find a user by its email (used for authentication)

func (*User) FindByID

func (u *User) FindByID(db *sql.DB) error

FindByID allows us to find a user by its id (used for authentication)

func (*User) GetMapRepresentation

func (u *User) GetMapRepresentation() map[string]interface{}

GetMapRepresentation return the json representation of the user without secret informations

func (*User) HashPassword

func (u *User) HashPassword() error

HashPassword hashes the user's password using bcrypt

func (*User) UpdatePassword

func (u *User) UpdatePassword(db *sql.DB, password string) error

UpdatePassword edits the user's password in memory and in db

func (*User) UpdateStatus

func (u *User) UpdateStatus(db *sql.DB, confirm bool) error

UpdateStatus edits the user's confirmation status

func (*User) ValidateResetToken

func (u *User) ValidateResetToken(db *sql.DB, secret, token string) error

ValidateResetToken is used to validate a reset token

Jump to

Keyboard shortcuts

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