// Returns nil if there is no session user func OfSession(context *view.Context) (userDoc interface{}) { if context.User != nil { return context.User } // if userDoc, ok := context.Cached(ContextCacheKey); ok { // return userDoc // } id, ok := context.SessionID() if !ok { return nil } userDoc, _, _ = FindByID(id) context.User = userDoc return userDoc }
func Logout(context *view.Context) { context.DeleteSessionID() //context.DeleteCached(ContextCacheKey) context.User = nil }
func Login(context *view.Context, userDoc interface{}) { context.SetSessionID(userDoc.(mongo.Document).ObjectId().Hex()) //context.Cache(ContextCacheKey, userDoc) context.User = userDoc }