auth

Paddy 2014-11-11 Child:d43c3fbf00f3

70:8398c3e4b3d9 Go to Latest

auth/session.go

Actually define Sessions. That last commit (42bc3e44f4fe) didn't actually include Sessions. Oops. Add the file and include our Session definition and sessionStore.

History
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/session.go	Tue Nov 11 21:15:04 2014 -0500
     1.3 @@ -0,0 +1,36 @@
     1.4 +package auth
     1.5 +
     1.6 +import (
     1.7 +	"errors"
     1.8 +	"time"
     1.9 +
    1.10 +	"code.secondbit.org/uuid"
    1.11 +)
    1.12 +
    1.13 +var (
    1.14 +	// ErrNoSessionStore is returned when a Context tries to act on a sessionStore without setting on first.
    1.15 +	ErrNoSessionStore = errors.New("no sessionStore was specified for the Context")
    1.16 +	// ErrSessionNotFound is returned when a Session is requested but not found in the sessionStore.
    1.17 +	ErrSessionNotFound = errors.New("session not found in sessionStore")
    1.18 +	// ErrInvalidSession is returned when a Session is specified but is not valid.
    1.19 +	ErrInvalidSession = errors.New("session is not valid")
    1.20 +)
    1.21 +
    1.22 +// Session represents a user's authenticated session, associating it with a profile
    1.23 +// and some audit data.
    1.24 +type Session struct {
    1.25 +	ID        string
    1.26 +	IP        string
    1.27 +	UserAgent string
    1.28 +	ProfileID uuid.ID
    1.29 +	Created   time.Time
    1.30 +	Login     string
    1.31 +	Active    bool
    1.32 +}
    1.33 +
    1.34 +type sessionStore interface {
    1.35 +	createSession(session Session) error
    1.36 +	getSession(id string) (Session, error)
    1.37 +	removeSession(id string) error
    1.38 +	listSessions(profile uuid.ID, before time.Time, num int64) ([]Session, error)
    1.39 +}