auth
2014-11-11
Child:d43c3fbf00f3
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.
| paddy@70 | 1 package auth |
| paddy@70 | 2 |
| paddy@70 | 3 import ( |
| paddy@70 | 4 "errors" |
| paddy@70 | 5 "time" |
| paddy@70 | 6 |
| paddy@70 | 7 "code.secondbit.org/uuid" |
| paddy@70 | 8 ) |
| paddy@70 | 9 |
| paddy@70 | 10 var ( |
| paddy@70 | 11 // ErrNoSessionStore is returned when a Context tries to act on a sessionStore without setting on first. |
| paddy@70 | 12 ErrNoSessionStore = errors.New("no sessionStore was specified for the Context") |
| paddy@70 | 13 // ErrSessionNotFound is returned when a Session is requested but not found in the sessionStore. |
| paddy@70 | 14 ErrSessionNotFound = errors.New("session not found in sessionStore") |
| paddy@70 | 15 // ErrInvalidSession is returned when a Session is specified but is not valid. |
| paddy@70 | 16 ErrInvalidSession = errors.New("session is not valid") |
| paddy@70 | 17 ) |
| paddy@70 | 18 |
| paddy@70 | 19 // Session represents a user's authenticated session, associating it with a profile |
| paddy@70 | 20 // and some audit data. |
| paddy@70 | 21 type Session struct { |
| paddy@70 | 22 ID string |
| paddy@70 | 23 IP string |
| paddy@70 | 24 UserAgent string |
| paddy@70 | 25 ProfileID uuid.ID |
| paddy@70 | 26 Created time.Time |
| paddy@70 | 27 Login string |
| paddy@70 | 28 Active bool |
| paddy@70 | 29 } |
| paddy@70 | 30 |
| paddy@70 | 31 type sessionStore interface { |
| paddy@70 | 32 createSession(session Session) error |
| paddy@70 | 33 getSession(id string) (Session, error) |
| paddy@70 | 34 removeSession(id string) error |
| paddy@70 | 35 listSessions(profile uuid.ID, before time.Time, num int64) ([]Session, error) |
| paddy@70 | 36 } |