Module: InterceptApi

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/concerns/intercept_api.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) intercept_api

TODO: Fix in API issues



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/concerns/intercept_api.rb', line 21

def intercept_api
  if /^\/api/ =~ request.path
    if token_authenticate
      render(json: {success: false}, status: :bad_request) && return unless set_project_from_params
    else
      render(json: {success: false}, status: :unauthorized) && return
    end
  end

  headers['Access-Control-Allow-Origin'] = '*'
  headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
  headers['Access-Control-Request-Method'] = '*'
  headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'

  true
end

- (Object) token_authenticate



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/concerns/intercept_api.rb', line 8

def token_authenticate
  t = params[:token]

  unless t
    authenticate_with_http_token do |token, _options|
      t = token
    end
  end

  @sessions_current_user = User.find_by_api_access_token(t) if t
end