Sha256: 10028eecb9f244efac91b4e92a59b8d4ef47e6fc4f6c3fb2b5d32dcc8795d0e2

Contents?: true

Size: 978 Bytes

Versions: 12

Compression:

Stored size: 978 Bytes

Contents

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

  before_action :set_current_request_details
  before_action :authenticate

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

    def set_current_request_details
      Current.user_agent = request.user_agent
      Current.ip_address = request.ip
    end
    <%- 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 -%>
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
authentication-zero-3.0.2 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-3.0.1 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-3.0.0 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-3.0.0.alpha1 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.36 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.35 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.34 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.33 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.32 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.31 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.30 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.29 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt