models

package
v0.0.0-...-22b4903 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2014 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package models provides the backing data models for the Phi Mu Alpha Sinfonia - Delta Iota chapter website.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPassword is returned when password authentication fails for a
	// specified User.
	ErrInvalidPassword = errors.New("invalid password")
)

Functions

This section is empty.

Types

type EmptyFieldError

type EmptyFieldError struct {
	Field string
}

EmptyFieldError is returned when a field fails a call to Validate due to empty input data.

The struct contains the name of the field which failed.

func (*EmptyFieldError) Error

func (e *EmptyFieldError) Error() string

Error returns a string representation of an EmptyFieldError.

type InvalidFieldError

type InvalidFieldError struct {
	Field   string
	Err     error
	Details string
}

InvalidFieldError is returned when a field fails a call to Validate due to invalid input data.

The struct contains the name of the field which failed, human-readable details regarding its failure, and if possible, the error which caused the failure to be triggered.

func (*InvalidFieldError) Error

func (e *InvalidFieldError) Error() string

Error returns a string representation of an InvalidFieldError.

type Notification

type Notification struct {
	ID        uint64 `db:"id" json:"id"`
	UserID    uint64 `db:"user_id" json:"userId"`
	Timestamp uint64 `db:"timestamp" json:"timestamp"`
	Read      bool   `db:"read" json:"read"`
	Text      string `db:"text" json:"text"`
	URI       string `db:"uri" json:"uri"`
}

Notification represents an application notification.

func (*Notification) SQLReadFields

func (n *Notification) SQLReadFields() []interface{}

SQLReadFields returns the correct field order to scan SQL row results into the receiving Notification struct.

func (*Notification) SQLWriteFields

func (n *Notification) SQLWriteFields() []interface{}

SQLWriteFields returns the correct field order for SQL write actions (such as insert or update), for the receiving Notification struct.

type Session

type Session struct {
	ID     uint64 `db:"id" json:"id"`
	UserID uint64 `db:"user_id" json:"userId"`
	Key    string `db:"key" json:"key"`
	Expire uint64 `db:"expire" json:"expire"`
}

Session represents an application session.

func NewSession

func NewSession(userID uint64, password string, expire time.Time) (*Session, error)

NewSession creates a new session for the specified user ID, which will expire at the specified time.

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns if the current session is expired; meaning that the current UNIX timestamp is greater than the one set for the session.

func (*Session) SQLReadFields

func (s *Session) SQLReadFields() []interface{}

SQLReadFields returns the correct field order to scan SQL row results into the receiving Session struct.

func (*Session) SQLWriteFields

func (s *Session) SQLWriteFields() []interface{}

SQLWriteFields returns the correct field order for SQL write actions (such as insert or update), for the receiving Session struct.

func (*Session) SetExpire

func (s *Session) SetExpire(expire time.Time)

SetExpire sets the expiration timestamp of the receiving Session struct to the UNIX timestamp equivalent of the input time.Time value.

type User

type User struct {
	ID        uint64 `db:"id" json:"id"`
	Username  string `db:"username" json:"username"`
	FirstName string `db:"first_name" json:"firstName"`
	LastName  string `db:"last_name" json:"lastName"`
	Email     string `db:"email" json:"email"`
	Phone     string `db:"phone" json:"phone"`
	Password  string `db:"password" json:"password,omitempty"`
}

User represents a user of the application.

func (*User) CopyFrom

func (u *User) CopyFrom(user *User)

CopyFrom copies fields from an input User into the receiving User struct.

func (*User) NewSession

func (u *User) NewSession(expire time.Time) (*Session, error)

NewSession generates a new Session for this user.

func (*User) SQLReadFields

func (u *User) SQLReadFields() []interface{}

SQLReadFields returns the correct field order to scan SQL row results into the receiving User struct.

func (*User) SQLWriteFields

func (u *User) SQLWriteFields() []interface{}

SQLWriteFields returns the correct field order for SQL write actions (such as insert or update), for the receiving User struct.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword hashes the input password using bcrypt, storing the password within the receiving User struct.

func (*User) TryPassword

func (u *User) TryPassword(password string) error

TryPassword attempts to verify the input password against the receiving User's current password.

func (*User) Validate

func (u *User) Validate() error

Validate verifies that all fields for the receiving User struct contain valid input.

type Validator

type Validator interface {
	Validate() error
}

Validator provides the Validate method, which ensures that fields on a struct contain valid values. An error is returned if any values are not valid.

Jump to

Keyboard shortcuts

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