sessionmanager

package
v0.0.0-...-9fcd9d5 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

func InitMockSessions

func InitMockSessions(db SessionsDB, clock utilities.Clock) SessionManager

Mock for tests

func InitSessions

func InitSessions(maxAge int, mongoDB *mgo.Session, dbName, collectionName string, clock utilities.Clock) SessionManager

Initialization of the mongo database, have to set maxage in minute.

func (*SessionManager) DeleteSessionKey

func (sm *SessionManager) DeleteSessionKey(token string) bool

Deletes session token from the database, sets user offline.

func (*SessionManager) GetUser

func (sm *SessionManager) GetUser(token string) string

func (*SessionManager) IsSessionLegit

func (sm *SessionManager) IsSessionLegit(token string) (model.Token, bool)

Checks if Session is in the database, and its still valid, it also refreshes the tokens life and sets the user to online state.

func (*SessionManager) SetSessionKeys

func (sm *SessionManager) SetSessionKeys(ClientIP string, username string) (string, error)

This is the function which generates a token and returns it, The token is automaticaly added to the connected mongoDB and it is added to the local cache.

type SessionRepo

type SessionRepo struct {
	// contains filtered or unexported fields
}

func NewSessionRepo

func NewSessionRepo(db *mgo.Collection) SessionRepo

func (SessionRepo) FindByTimeAccessed

func (s SessionRepo) FindByTimeAccessed(duration time.Duration) *mgo.Iter

func (SessionRepo) FindByToken

func (s SessionRepo) FindByToken(token string, profile *model.Token) bool

func (SessionRepo) Insert

func (s SessionRepo) Insert(token, userName string, t time.Time) error

func (SessionRepo) Remove

func (s SessionRepo) Remove(token string) error

func (SessionRepo) RemoveAll

func (s SessionRepo) RemoveAll(duration time.Duration) error

func (SessionRepo) Update

func (s SessionRepo) Update(token string, t time.Time) error

type SessionsDB

type SessionsDB interface {
	FindByToken(token string, profile *model.Token) bool
	FindByTimeAccessed(duration time.Duration) *mgo.Iter
	RemoveAll(duration time.Duration) error
	Update(token string, t time.Time) error
	Insert(token, userName string, t time.Time) error
	Remove(token string) error
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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