database

package
v0.0.0-...-f7a2401 Latest Latest
Warning

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

Go to latest
Published: May 6, 2017 License: MIT Imports: 16 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound = errors.New("account not found")
	ErrEmailExists     = errors.New("email already exists")
	ErrNoDatabase      = errors.New("no database connection details")
	ErrNoPasswordGiven = errors.New("a password is required")
)
View Source
var TOKEN_LENGTH = 32

Functions

func EmailExists

func EmailExists(db Database, a *Account) error

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

Types

type Account

type Account struct {
	ID                 string `db:"id"`
	Name               string `validate:"required"`
	Email              string `validate:"required"`
	HashedPassword     string `db:"hashed_password"`
	ConfirmationToken  string
	PasswordResetToken string
	Images             []*image_service.Image
	Metadata           map[string]string
	CreatedAt          time.Time `db:"created_at"`
}

func (*Account) BeforeInsert

func (a *Account) BeforeInsert(db orm.DB) error

func (*Account) ComparePasswordToHash

func (a *Account) ComparePasswordToHash(password string) error

func (*Account) HashPassword

func (a *Account) HashPassword(password string) error

func (*Account) Valid

func (a *Account) Valid() error

type Database

type Database interface {
	List(count int32, token string) ([]*Account, string, error)
	ReadByID(ID string) (*Account, error)
	ReadByEmail(email string) (*Account, error)
	Create(a *Account, password string) error
	Update(a *Account) error
	Delete(ID string) error
	Confirm(token string) (*Account, error)
	GeneratePasswordToken(email string) (*Account, error)
	UpdatePassword(string, string) (*Account, error)
	Migrate() error
	Truncate() error
	Close() error
}

func DatabaseFromEnv

func DatabaseFromEnv() Database

type PostgreSQL

type PostgreSQL struct {
	Database
	// contains filtered or unexported fields
}

func (*PostgreSQL) Close

func (p *PostgreSQL) Close() error

func (*PostgreSQL) Confirm

func (p *PostgreSQL) Confirm(token string) (*Account, error)

func (*PostgreSQL) Connect

func (p *PostgreSQL) Connect(conn string) error

func (*PostgreSQL) Create

func (p *PostgreSQL) Create(a *Account, password string) error

func (*PostgreSQL) Delete

func (p *PostgreSQL) Delete(ID string) error

func (*PostgreSQL) GeneratePasswordToken

func (p *PostgreSQL) GeneratePasswordToken(email string) (*Account, error)

func (*PostgreSQL) List

func (p *PostgreSQL) List(count32 int32, token string) (accounts []*Account, next_token string, err error)

func (*PostgreSQL) Migrate

func (p *PostgreSQL) Migrate() error

func (*PostgreSQL) ReadByEmail

func (p *PostgreSQL) ReadByEmail(email string) (*Account, error)

func (*PostgreSQL) ReadByID

func (p *PostgreSQL) ReadByID(ID string) (*Account, error)

func (*PostgreSQL) Truncate

func (p *PostgreSQL) Truncate() error

func (*PostgreSQL) Update

func (p *PostgreSQL) Update(a *Account) error

func (*PostgreSQL) UpdatePassword

func (p *PostgreSQL) UpdatePassword(token, hashed_password string) (*Account, error)

Jump to

Keyboard shortcuts

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