sessions

package
v0.0.0-...-6c63854 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sessions contains a Session type used to track session cookies in HTTP responses.

Each session will have a unique selector and session ID, be attached to a single user account, and can be persistent or session only.

This package should be not be uses without seshandler which manages sessions for a server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Session

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

Session type represents an HTTP session.

func NewSession

func NewSession(selectorID, sessionID, username, encryptedUsername, sessionCookieName string, maxLifetime time.Duration) *Session

NewSession creates a new session with the given information

func (*Session) AddError

func (s *Session) AddError(err ...interface{})

AddError adds an error to the session flashes

func (*Session) AddMessage

func (s *Session) AddMessage(msg ...interface{})

AddMessage adds an error to the session flashes

func (*Session) CookieValue

func (s *Session) CookieValue() string

CookieValue returns the value of the cookie to send with the response

func (*Session) Destroy

func (s *Session) Destroy()

Destroy destroys a session.

func (*Session) EncryptedUsername

func (s *Session) EncryptedUsername() string

EncryptedUsername returns the username of the account to which the session is associated.

func (*Session) Equals

func (s *Session) Equals(other *Session, hash func(string) string) bool

Equals returns whether other session is equal to this session

func (*Session) ExpireTime

func (s *Session) ExpireTime() time.Time

ExpireTime returns the time that the session will expire.

func (*Session) Flashes

func (s *Session) Flashes() ([]interface{}, []interface{})

Flashes gets and deletes the flash messages.

func (*Session) HashPayload

func (s *Session) HashPayload() string

HashPayload returns the string related to the session to be hashed.

func (*Session) IsDestroyed

func (s *Session) IsDestroyed() bool

IsDestroyed returns whether the session has been destroyed

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired returns whether the session is expired.

func (*Session) IsPersistent

func (s *Session) IsPersistent() bool

IsPersistent returns whether the session is a persistent one.

func (*Session) IsUserLoggedIn

func (s *Session) IsUserLoggedIn() bool

IsUserLoggedIn returns true if the user is logged in

func (*Session) IsValid

func (s *Session) IsValid() bool

IsValid returns whether the session is valid A session is valid if it is neither destroyed nor expired.

func (*Session) LogUserIn

func (s *Session) LogUserIn(username, encryptedUsername string) error

LogUserIn logs a user into a session. It returns a non-nil error if there is already a user logged into that session.

func (*Session) LogUserOut

func (s *Session) LogUserOut()

LogUserOut logs a user out of a session.

func (*Session) MarkSessionExpired

func (s *Session) MarkSessionExpired()

MarkSessionExpired marks the session expired.

func (*Session) SelectorID

func (s *Session) SelectorID() string

SelectorID returns the session's selector ID

func (*Session) SessionCookie

func (s *Session) SessionCookie() *http.Cookie

SessionCookie builds a cookie from the Session struct

func (*Session) SessionID

func (s *Session) SessionID() string

SessionID returns the session's session ID

func (*Session) TextToValues

func (s *Session) TextToValues(text string) error

TextToValues converts the string to a values map for the session. It returns an error if the string cannot be converted.

func (*Session) UpdateExpireTime

func (s *Session) UpdateExpireTime(maxLifetime time.Duration)

UpdateExpireTime updates the time that the session expires

func (*Session) Username

func (s *Session) Username() string

Username returns the username of the account to which the session is associated.

func (*Session) ValuesAsText

func (s *Session) ValuesAsText() string

ValuesAsText converts the values into text for storage in a database.

Jump to

Keyboard shortcuts

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