Sha256: ea1487ea5c33b2e99522a2307c673745d09b5d474f90dad2fb13be168d295446

Contents?: true

Size: 946 Bytes

Versions: 11

Compression:

Stored size: 946 Bytes

Contents

class ApplicationController < ActionController::API
  include ActionController::HttpAuthentication::Token::ControllerMethods

  before_action :set_current_request_details
  before_action :authenticate
  <%- if options.lockable? %>
  def require_lock(wait: 1.hour, attempts: 10)
    counter = Kredis.counter("require_lock:#{request.remote_ip}:#{controller_path}:#{action_name}", expires_in: wait)
    counter.increment

    if counter.value > attempts
      render json: { error: "You've exceeded the maximum number of attempts" }, status: :too_many_requests
    end
  end
  <%- end -%>

  private
    def authenticate
      if session = authenticate_with_http_token { |token, _| Session.find_signed(token) }
        Current.session = session
      else
        request_http_token_authentication
      end
    end

    def set_current_request_details
      Current.user_agent = request.user_agent
      Current.ip_address = request.ip
    end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
authentication-zero-2.16.19 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.18 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.17 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.16 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.15 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.14 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.13 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.12 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.11 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.10 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.9 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt