示例#1
0
func (self *Auth) Authenticate(context *view.Context) (ok bool, err error) {
	id, ok := context.SessionID()
	if !ok {
		return false, nil
	}

	ok, err = IsConfirmedUserID(id)
	if !ok && err == nil && self.LoginURL != nil {
		err = view.Redirect(self.LoginURL.URL(context.PathArgs...))
	}
	return ok, err
}
示例#2
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
}