Documentation ¶
Overview ¶
Package cookies uses the DatabaseCookieStore type as its default cookie store for managing user sessions
Index ¶
- Variables
- func ConfigureTokenExpireTime(expireTime time.Duration)
- func InitCookieStore()
- func SetCookieStore(store CookieStore)
- type Client
- type CookieStore
- type DatabaseCookieStore
- func (store *DatabaseCookieStore) DeleteCookie(cookie *Session) error
- func (store *DatabaseCookieStore) GetAllUserCookies(userID bson.ObjectId) ([]*Session, error)
- func (store *DatabaseCookieStore) Init()
- func (store *DatabaseCookieStore) ReadCookie(key string) (*Session, error)
- func (store *DatabaseCookieStore) WriteCookie(cookie *Session) error
- type FileCookieStore
- func (store *FileCookieStore) DeleteCookie(cookie *Session) error
- func (store *FileCookieStore) GetAllUserCookies(userID bson.ObjectId) ([]*Session, error)
- func (store *FileCookieStore) Init()
- func (store *FileCookieStore) ReadCookie(key string) (*Session, error)
- func (store *FileCookieStore) WriteCookie(cookie *Session) error
- type Session
Constants ¶
This section is empty.
Variables ¶
var (
ErrInitializationFailed = errors.New("Initialization of the cookie store has failed")
)
Errors generated by the cookie stores
var (
ErrTokenExpired = errors.New("The session token has expired")
)
Errors generated during session handling
Functions ¶
func ConfigureTokenExpireTime ¶
ConfigureTokenExpireTime is used to change the default cofiguration of token expiration times
func InitCookieStore ¶
func InitCookieStore()
InitCookieStore initializes the currently active cookie store
func SetCookieStore ¶
func SetCookieStore(store CookieStore)
SetCookieStore sets the cookie store that will be used by the system. If this method is not called, the default cookie store will be used
Types ¶
type Client ¶
type Client struct { Address string `bson:"address,omitempty" json:"address"` Type string `bson:"type,omitempty" json:"type"` Name string `bson:"name,omitempty" json:"name"` Version string `bson:"version,omitempty" json:"version"` OS string `bson:"os,omitempty" json:"os"` IsMobileDevice bool `bson:"isMobileDevice,omitempty" json:"isMobileDevice"` }
Client struct contains information regarding the client that has made the http request
func UnknownClientDetails ¶
func UnknownClientDetails() *Client
UnknownClientDetails gets the default client details, which have 'unknown' values
type CookieStore ¶
type CookieStore interface { ReadCookie(key string) (*Session, error) WriteCookie(cookie *Session) error DeleteCookie(cookie *Session) error GetAllUserCookies(userID bson.ObjectId) ([]*Session, error) Init() }
CookieStore is an interface used for describing entities that can manage the location of user sessions (cookies) and performs operations such as reading or writing cookie from/to that location
type DatabaseCookieStore ¶
type DatabaseCookieStore struct {
// contains filtered or unexported fields
}
DatabaseCookieStore manages cookies using a database
func NewDatabaseCookieStore ¶
func NewDatabaseCookieStore(storeLocation string) *DatabaseCookieStore
NewDatabaseCookieStore creates a new DatabaseCookieStore pointer entity
func (*DatabaseCookieStore) DeleteCookie ¶
func (store *DatabaseCookieStore) DeleteCookie(cookie *Session) error
DeleteCookie deletes a cookie from the cookie storage
func (*DatabaseCookieStore) GetAllUserCookies ¶
func (store *DatabaseCookieStore) GetAllUserCookies(userID bson.ObjectId) ([]*Session, error)
GetAllUserCookies returns all the cookies that a certain user has
func (*DatabaseCookieStore) Init ¶
func (store *DatabaseCookieStore) Init()
Init initializes the cookie store
func (*DatabaseCookieStore) ReadCookie ¶
func (store *DatabaseCookieStore) ReadCookie(key string) (*Session, error)
ReadCookie fetches a cookie from the cookie store
func (*DatabaseCookieStore) WriteCookie ¶
func (store *DatabaseCookieStore) WriteCookie(cookie *Session) error
WriteCookie writes a cookie in the cookie store. If that cookie already exists, it is overwritten
type FileCookieStore ¶
type FileCookieStore struct {
// contains filtered or unexported fields
}
FileCookieStore manages cookies using files on the local drive
func NewFileCookieStore ¶
func NewFileCookieStore(storeLocation string) *FileCookieStore
NewFileCookieStore creates a new NewFileCookieStore pointer entity
func (*FileCookieStore) DeleteCookie ¶
func (store *FileCookieStore) DeleteCookie(cookie *Session) error
DeleteCookie deletes a cookie from the cookie storage
func (*FileCookieStore) GetAllUserCookies ¶
func (store *FileCookieStore) GetAllUserCookies(userID bson.ObjectId) ([]*Session, error)
GetAllUserCookies returns all the cookies that a certain user has
func (*FileCookieStore) Init ¶
func (store *FileCookieStore) Init()
Init initializes the cookie store
func (*FileCookieStore) ReadCookie ¶
func (store *FileCookieStore) ReadCookie(key string) (*Session, error)
ReadCookie fetches a cookie from the cookie store
func (*FileCookieStore) WriteCookie ¶
func (store *FileCookieStore) WriteCookie(cookie *Session) error
WriteCookie writes a cookie in the cookie store. If that cookie already exists, it is overwritten
type Session ¶
type Session struct { ID bson.ObjectId `bson:"_id" json:"-"` UserID bson.ObjectId `bson:"userID,omitempty" json:"userID"` Token string `bson:"token,omitempty" json:"token"` AccountType int `bson:"accountType,omitempty" json:"accountType"` ExpireTime time.Time `bson:"expireTime,omitempty" json:"-"` Client *Client `bson:"client,omitempty" json:"client"` }
Session is a struct representing the session that a user has. Sessions are active since login until they expire or the user disconnects
func GetSession ¶
GetSession retrieves a session from the cookie store
func GetUserSessions ¶
GetUserSessions retrieves all the sessions that a user has
func NewSession ¶
NewSession generates a new Session pointer that contains the given userID and a unique token used as an identifier
func (*Session) IsUserInRole ¶
IsUserInRole verifies if the user with the current session has a specific role
func (*Session) ResetToken ¶
ResetToken generates a new token and resets the expire time target of the session This also triggers a Save() action, to update the cookie store