session

package
v0.0.0-...-9008a76 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LogInSession redis.Store

LogInSession is a redis store for user sessions

Functions

func AuthRequired

func AuthRequired() gin.HandlerFunc

AuthRequired is a middleware to check there is a logged in user in the current session

func ClearUserID

func ClearUserID(c *gin.Context)

ClearUserID remove a user session (effectively logging out the user)

func GetCSRFTokenInput

func GetCSRFTokenInput(c *gin.Context) template.HTML

GetCSRFTokenInput returns a hidden input tag with the token

func GetUserID

func GetUserID(c *gin.Context) string

GetUserID returns the user ID of an authenticated request

func SetUserID

func SetUserID(c *gin.Context, userID string)

SetUserID sets a userId to a session (effectivly logging in the user)

func Setup

func Setup(conf *Conf) error

Setup initializes the global `LogInSession` redis.Store instance

func Use

func Use(r gin.IRoutes, conf *Conf)

Use adds the session and csrf token middleware

Types

type Conf

type Conf struct {
	RedisConf  RedisConf
	CsrfSecret string
	IsDevelop  bool
}

Conf maintains the session configuration

type RedisConf

type RedisConf struct {
	MaxIdleConnections int
	Host               string
	Password           string
	SecretKeyPair      string
}

RedisConf contains the configuration to maintain user session backed by a Redis server

Jump to

Keyboard shortcuts

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