Пример #1
0
func findUsernameFromSessionID(sessionID string) (string, error) {
	session, err := modelhelper.GetSession(sessionID)
	if err != nil {
		return "", err
	}

	return session.Username, nil
}
Пример #2
0
func getSession(r *http.Request) (*models.Session, error) {
	cookie, err := r.Cookie("clientId")
	if err != nil {
		return "", ErrClientIdNotFound
	}

	if cookie.Value == "" {
		return "", ErrCookieValueNotFound
	}

	session, err := modelhelper.GetSession(cookie.Value)
	if err != nil {
		return "", ErrSessionNotFound
	}

	return session, nil
}
Пример #3
0
func (s *SessionCache) ById(id string) (*mongomodels.Session, error) {
	data, err := s.session.Get(id)
	if err != nil && err != cache.ErrNotFound {
		return nil, err
	}

	if err == nil {
		ses, ok := data.(*mongomodels.Session)
		if ok {
			return ses, nil
		}
	}

	session, err := modelhelper.GetSession(id)
	if err != nil {
		return nil, err
	}

	if err := s.SetToCache(session); err != nil {
		return nil, err
	}

	return session, nil
}