Module: Core::Helpers::Sessions

Included in:
Controllers::Base
Defined in:
lib/core/helpers/sessions.rb

Overview

This helper gives access to methods about user's session on the API.

Author:

Instance Method Summary collapse

Instance Method Details

#sessionArkaan::Authentication::Session

Checks the session of the user requesting the API and returns an error if it either not exists with the given token, or the token is not given.

Returns:

  • (Arkaan::Authentication::Session)

    the current session of the user.

Raises:

  • (Virtuatable::API::Errors::NotFound)

    if the session is not found or the token not given in the parameters of the request.

  • (Virtuatable::API::Errors::BadRequest)

    if the session token is not correctly given in the parameters.



17
18
19
20
21
22
23
# File 'lib/core/helpers/sessions.rb', line 17

def session
  return @session unless @session.nil?

  check_presence 'session_id'
  @session = session_model.find_by(token: params['session_id'])
  @session.nil? ? api_not_found('session_id.unknown') : @session
end

#session_modelObject



25
26
27
# File 'lib/core/helpers/sessions.rb', line 25

def session_model
  Arkaan::Authentication::Session
end