Sha256: ff46a48b1fb6c76d72ab4cad5a95e31a97109ab4d6edf41a80bcffee30c32816

Contents?: true

Size: 1.25 KB

Versions: 9

Compression:

Stored size: 1.25 KB

Contents

module GoogleAuthenticatorRails
  module ActionController
    class RailsAdapter
      class LoadedTooLateError < StandardError
        def initialize
          super("GoogleAuthenticatorRails is trying to prepend a before_filter in ActionController::Base.  Because you've already defined" +
          " ApplicationController, your controllers will not get this before_filter.  Please load GoogleAuthenticatorRails before defining" +
          " ApplicationController.")
        end
      end

      def initialize(controller)
        @controller = controller
      end

      def cookies
        @controller.send(:cookies)
      end
    end

    module Integration
      def self.included(klass)
        raise RailsAdapter::LoadedTooLateError.new if defined?(::ApplicationController)

        method = klass.respond_to?(:prepend_before_action) ? :prepend_before_action : :prepend_before_filter
        klass.send(method, :activate_google_authenticator_rails)
      end

      private
      def activate_google_authenticator_rails
        GoogleAuthenticatorRails::Session::Base.controller = RailsAdapter.new(self)
      end
    end
  end
end

if defined?(ActionController::Base)
  ActionController::Base.send(:include, GoogleAuthenticatorRails::ActionController::Integration)
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
google-authenticator-rails-1.7.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-2.0.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.5.1 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.6.1 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.6.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.5.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.4.1 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.4.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb
google-authenticator-rails-1.3.0 lib/google-authenticator-rails/action_controller/rails_adapter.rb