session

package
v0.0.0-...-dc37515 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2021 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SessionCookieName is the name of the session cookie.
	SessionCookieName = "session"
)

Variables

This section is empty.

Functions

func CSRFTokenMiddleware

func CSRFTokenMiddleware() negroni.HandlerFunc

CSRFTokenMiddleware enforces a CSRF token in the ?token= part of the URL.

func GenerateCSRFToken

func GenerateCSRFToken() string

GenerateCSRFToken generates a new csrf token.

func GenerateSid

func GenerateSid(id uuid.UUID) string

GenerateSid generates a new session id.

The session id gets prefixed with the user id, so sessions can be invalidated for an user in case an account gets blocked or deleted.

func GetSid

func GetSid(r *http.Request) *string

GetSid returns the session id from the current request context.

func MustBeAnonymousMiddleware

func MustBeAnonymousMiddleware() negroni.HandlerFunc

MustBeAnonymousMiddleware only lets the request proceed if the account is not logged in.

func MustBeLoggedInMiddleware

func MustBeLoggedInMiddleware() negroni.HandlerFunc

MustBeLoggedInMiddleware only lets the request proceed if an account is logged in.

Types

type Middleware

type Middleware struct {
	SecureCookie bool
	CookieName   string
	// contains filtered or unexported fields
}

Middleware is the session middleware.

func NewMiddleware

func NewMiddleware(logger logrus.FieldLogger, store keyvalue.Store) *Middleware

func (*Middleware) DeleteSession

func (m *Middleware) DeleteSession(w http.ResponseWriter, r *http.Request)

DeleteSession removes the current session.

func (*Middleware) RegenerateSession

func (m *Middleware) RegenerateSession(w http.ResponseWriter, r *http.Request, id uuid.UUID) error

RegenerateSession invalidates the previous session and creates a new one.

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)

type Session

type Session struct {
	ID        uuid.UUID
	CSRFToken string
}

Session represents the session that is saved to the key-value storage.

func Get

func Get(r *http.Request) *Session

Get returns the session from the current request context.

func (*Session) GetCSRFToken

func (s *Session) GetCSRFToken() string

func (*Session) LoggedIn

func (s *Session) LoggedIn() bool

func (*Session) Read

func (s *Session) Read(p []byte) (int, error)

func (*Session) WriteTo

func (s *Session) WriteTo(w io.Writer) (int64, error)

Jump to

Keyboard shortcuts

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