sessions

package
v0.0.0-...-9818b01 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2017 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CodeLen = 16

CodeLen is the number of random bytes used for the session codes

View Source
const SessionContextKey = "session"

SessionContextKey name of the session in echo.Context

View Source
const SessionCookieName = "cozysessid"

SessionCookieName : name of the cookie created by cozy

View Source
const SessionMaxAge = 7 * 24 * 60 * 60

SessionMaxAge : duration of the session

Variables

View Source
var (
	// ErrNoCookie is returned by GetSession if there is no cookie
	ErrNoCookie = errors.New("No session cookie")
	// ErrInvalidID is returned by GetSession if the cookie contains wrong ID
	ErrInvalidID = errors.New("Session cookie has wrong ID")
)

Functions

This section is empty.

Types

type Code

type Code struct {
	Value     string
	SessionID string
	AppHost   string
	ExpiresAt int64
}

A Code is used to transfer a session from the domain with the stack to a subdomain of an application, when the flat subdomains structure is used. The code is valid:

  • only once
  • for a short time span (1 minute)
  • just for one application.

func BuildCode

func BuildCode(sessionID, app string) *Code

BuildCode creates a session code for the given session and app

func FindCode

func FindCode(value, app string) *Code

FindCode tries to find a valid pending code. It also clears the pending codes of all the expired codes.

type Session

type Session struct {
	Instance *instance.Instance `json:"-"`
	DocID    string             `json:"_id,omitempty"`
	DocRev   string             `json:"_rev,omitempty"`
	LastSeen time.Time          `json:"last_seen,omitempty"`
	Closed   bool               `json:"closed"`
}

A Session is an instance opened in a browser

func GetSession

func GetSession(c echo.Context, i *instance.Instance) (*Session, error)

GetSession retrieves the session from a echo.Context

func New

func New(i *instance.Instance) (*Session, error)

New creates a session in couchdb for the given instance

func (*Session) Delete

func (s *Session) Delete(i *instance.Instance) *http.Cookie

Delete is a function to delete the session in couchdb, and returns a cookie with a negative MaxAge to clear it

func (*Session) DocType

func (s *Session) DocType() string

DocType implements couchdb.Doc

func (*Session) ID

func (s *Session) ID() string

ID implements couchdb.Doc

func (*Session) OlderThan

func (s *Session) OlderThan(t time.Duration) bool

OlderThan check if a session last seen is older than t from now

func (*Session) Rev

func (s *Session) Rev() string

Rev implements couchdb.Doc

func (*Session) SetID

func (s *Session) SetID(v string)

SetID implements couchdb.Doc

func (*Session) SetRev

func (s *Session) SetRev(v string)

SetRev implements couchdb.Doc

func (*Session) ToAppCookie

func (s *Session) ToAppCookie(domain string) (*http.Cookie, error)

ToAppCookie returns an http.Cookie for this Session on an app subdomain

func (*Session) ToCookie

func (s *Session) ToCookie() (*http.Cookie, error)

ToCookie returns an http.Cookie for this Session

Jump to

Keyboard shortcuts

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