parameters: (accept_key=False, optional=False, admin=False,
                     association=False)
return_statement: return _requires_login
docstring: Indicates that an endpoint requires the user to be logged in.
  
      :param accept_key: if True, then accept an API key, otherwise only accept
      a session cookie (OAuth).
      :param optional: if True, do not return HTTP 403 if the user is not
      logged in.
      :param admin: if True, only accept admin users.
      :param association: if True, only accept users that have associated and
      verified their email.
docstring_summary: Indicates that an endpoint requires the user to be logged in.
docstring_tokens: Indicates that an endpoint requires the user to be logged in .
function: def requires_login(accept_key=False, optional=False, admin=False,
                     association=False):
      """
      Indicates that an endpoint requires the user to be logged in.
  
      :param accept_key: if True, then accept an API key, otherwise only accept
      a session cookie (OAuth).
      :param optional: if True, do not return HTTP 403 if the user is not
      logged in.
      :param admin: if True, only accept admin users.
      :param association: if True, only accept users that have associated and
      verified their email.
      """
      def _requires_login(view):
          @functools.wraps(view)
          def decorated_view(*args, **kwargs):
              user = None
              if accept_key:
                  user = validate_api_key(
                      flask.request.headers.get(config.API_KEY_HEADER))
  
              if not user:
                  user = validate_session_cookie(
                      flask.session.get(config.SESSION_COOKIE))
  
              if user:
                  if admin and user["is_admin"]:
                      kwargs["user_id"] = user["user_id"]
                  elif admin:
                      raise util.APIError(
                          403, message="User cannot take this action.")
                  else:
                      kwargs["user_id"] = user["user_id"]
              elif optional:
                  kwargs["user_id"] = None
              else:
                  raise util.APIError(403, message="User not logged in.")
  
              return view(*args, **kwargs)
  
          return decorated_view
  
      return _requires_login
function_tokens: def requires_login ( accept_key = False , optional = False , admin = False , association = False ) : def _requires_login ( view ) : @ functools . wraps ( view ) def decorated_view ( * args , * * kwargs ) : user = None if accept_key : user = validate_api_key ( flask . request . headers . get ( config . API_KEY_HEADER ) ) if not user : user = validate_session_cookie ( flask . session . get ( config . SESSION_COOKIE ) ) if user : if admin and user [ "is_admin" ] : kwargs [ "user_id" ] = user [ "user_id" ] elif admin : raise util . APIError ( 403 , message = "User cannot take this action." ) else : kwargs [ "user_id" ] = user [ "user_id" ] elif optional : kwargs [ "user_id" ] = None else : raise util . APIError ( 403 , message = "User not logged in." ) return view ( * args , * * kwargs ) return decorated_view return _requires_login