sessions

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2021 License: ISC Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionMaxAge is the max age for a session in seconds.
	SessionMaxAge = 86400 // One day

)

Variables

View Source
var (
	// ErrSessionNotFound is emitted when a session is not found in the
	// session store.
	ErrSessionNotFound = errors.New("session not found")
)

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using slog.

Types

type Sessions

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

Sessions manages politeiawww sessions.

func New

func New(userdb user.Database, keyPairs ...[]byte) *Sessions

New returns a new Sessions context.

func (*Sessions) DelSession

func (s *Sessions) DelSession(w http.ResponseWriter, r *http.Request) error

DelSession removes the given session from the session store.

func (*Sessions) GetSession

func (s *Sessions) GetSession(r *http.Request) (*sessions.Session, error)

GetSession returns the Session for the session ID from the given http request cookie. If no session exists then a new session object is returned. Access IsNew on the session to check if it is an existing session or a new one. The new session will not have any sessions values set, such as user_id, and will not have been saved to the session store yet.

func (*Sessions) GetSessionUser

func (s *Sessions) GetSessionUser(w http.ResponseWriter, r *http.Request) (*user.User, error)

GetSessionUser returns the User for the given session. A errSessionFound error is returned if a user session does not exist or has expired.

func (*Sessions) GetSessionUserID

func (s *Sessions) GetSessionUserID(w http.ResponseWriter, r *http.Request) (string, error)

GetSessionUserID returns the user ID of the user for the given session. A ErrSessionNotFound error is returned if a user session does not exist or has expired.

func (*Sessions) NewSession

func (s *Sessions) NewSession(w http.ResponseWriter, r *http.Request, userID string) error

NewSession creates a new session, adds it to the given http response session cookie, and saves it to the session store. If the http request already contains a session cookie then the session values will be updated and the session will be updated in the session store.

Jump to

Keyboard shortcuts

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