session

package
v0.0.0-...-789275d Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2017 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UniqueIndex defines the unique index name used by the models db for model query optimization.
	UniqueIndex = "user_id"

	// UniqueIndexField defines the unique index field used by the model in it's field.
	UniqueIndexField = "user_public_id"
)

Variables

This section is empty.

Functions

func ParseToken

func ParseToken(val string) (userID string, token string, err error)

ParseToken parses the base64 encoded token, which it returns the associated userID and session token.

Types

type EndSession

type EndSession struct {
	UserID string `json:"user_id"`
	Token  string `json:"token"`
}

EndSession defines the set of data received to end a user's session.

type NewSession

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

NewSession defines the set of data received to create a new user's session.

type Session

type Session struct {
	UserID   string    `json:"user_id"`
	PublicID string    `json:"public_id"`
	Token    string    `json:"token"`
	Expires  time.Time `json:"expires"`
}

Session defines a struct which holds the the details of a giving user session.

func New

func New(userID string, expiration time.Time) *Session

New returns a new instance of a session.

func (*Session) Expired

func (u *Session) Expired() bool

Expired returns true/false if the the given session is expired.

func (Session) Fields

func (u Session) Fields() map[string]interface{}

Fields returns a map representing the data of the session.

func (Session) SessionFields

func (u Session) SessionFields() map[string]interface{}

SessionFields returns a map representing the user session.

func (Session) SessionToken

func (u Session) SessionToken() string

SessionToken returns the Session.Token has a base64 encoded string. It returns a base64 encoded version where it contains the UserID:SessionToken.

func (Session) Table

func (u Session) Table() string

Table returns the given table which the given struct corresponds to.

func (Session) ValidateToken

func (u Session) ValidateToken(token string) bool

ValidateToken validates the provide base64 encoded token, that it matches the expected token value with that of the session.

func (*Session) WithFields

func (u *Session) WithFields(fields map[string]interface{}) error

WithFields attempts to syncing the giving data within the provided map into it's own fields.

Jump to

Keyboard shortcuts

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