예제 #1
0
// 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
}
예제 #2
0
func Logout(context *view.Context) {
	context.DeleteSessionID()
	//context.DeleteCached(ContextCacheKey)
	context.User = nil
}
예제 #3
0
func Login(context *view.Context, userDoc interface{}) {
	context.SetSessionID(userDoc.(mongo.Document).ObjectId().Hex())
	//context.Cache(ContextCacheKey, userDoc)
	context.User = userDoc
}