session

package
v0.23.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: MIT Imports: 7 Imported by: 4

README

Nibbler Session

Provides a session for the server to use.

An SQL connector is available out of the box, which can be used in memory mode by not providing a DB reference.

The default MaxAge is 30 days (86400 * 30) in all cases (which is pretty long).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Extension

type Extension struct {
	nibbler.NoOpExtension
	SessionName    string
	StoreConnector StoreConnector // creates cookie store if not provided
	// contains filtered or unexported fields
}

func (*Extension) EnforceEmailValidated added in v0.19.0

func (s *Extension) EnforceEmailValidated(routerFunc func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

EnforceEmailValidated validates the user is logged in and that user's email has been validated. Note that the session extension can't validate emails, but extensions like the user-local-auth extension can

func (*Extension) EnforceLoggedIn added in v0.19.0

func (s *Extension) EnforceLoggedIn(routerFunc func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

func (*Extension) EnforceParamMatchesCallerID added in v0.19.0

func (s *Extension) EnforceParamMatchesCallerID(param string, routerFunc func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request)

EnforceParamMatchesCallerID will validate that the user is logged in and is requesting a resource that's identified by a user ID that matches the caller's ID. The param argument to this function determines which path param is checked against the caller's ID.

func (*Extension) GetAttribute

func (s *Extension) GetAttribute(r *http.Request, attribute string) (interface{}, error)

func (*Extension) GetCaller

func (s *Extension) GetCaller(r *http.Request) (*nibbler.User, error)

func (*Extension) GetName added in v0.14.0

func (s *Extension) GetName() string

func (*Extension) Init

func (s *Extension) Init(app *nibbler.Application) error

func (*Extension) SetAttribute

func (s *Extension) SetAttribute(w http.ResponseWriter, r *http.Request, key string, value interface{}) error

TODO: SetAttributes to set multiple attributes in one save

func (*Extension) SetCaller

func (s *Extension) SetCaller(w http.ResponseWriter, r *http.Request, userValue *nibbler.User) error

SetCaller puts the user into the session as the current user

type StoreConnector added in v0.10.0

type StoreConnector interface {
	Connect() (error, sessions.Store) // TODO: reverse param order
	MaxAge() int
}

Jump to

Keyboard shortcuts

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