Sha256: c65a8fc5d2208736c11f25d996d316682a9428874091648ec2e72ac0836d262c

Contents?: true

Size: 964 Bytes

Versions: 9

Compression:

Stored size: 964 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 = 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
    <%- 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

9 entries across 9 versions & 1 rubygems

Version Path
authentication-zero-2.16.28 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.27 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.26 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.25 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.24 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.23 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.22 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.21 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt
authentication-zero-2.16.20 lib/generators/authentication/templates/controllers/api/application_controller.rb.tt