Sha256: b0bef04db4c491bd0ee6313a015f3ac9d508b47540a4e0f28243a97d828fb601

Contents?: true

Size: 958 Bytes

Versions: 6

Compression:

Stored size: 958 Bytes

Contents

module Janus
  module Strategies
    extend ActiveSupport::Concern

    # Runs authentication strategies to log a user in.
    def run_strategies(scope)
      Janus::Manager.strategies.each { |name| break if run_strategy(name, scope) }
    end

    # Runs a given strategy and returns true if it succeeded.
    def run_strategy(name, scope)
      strategy = "Janus::Strategies::#{name.to_s.camelize}".constantize.new(scope, self)

      if strategy.valid?
        strategy.authenticate!

        if strategy.success?
          send(strategy.auth_method, strategy.user, :scope => scope)
          Janus::Manager.run_callbacks(:authenticate, strategy.user, self, :scope => scope)
        end
      end

      strategy.success?
    end

    module ClassMethods
      # Returns the list of strategies as underscore symbols.
      def strategies
        @strategies ||= [:rememberable, :remote_authenticatable, :token_authenticatable]
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
janus-0.10.1 lib/janus/strategies.rb
janus-0.10.0 lib/janus/strategies.rb
janus-0.9.1 lib/janus/strategies.rb
janus-0.9.0 lib/janus/strategies.rb
janus-0.8.1 lib/janus/strategies.rb
janus-0.8.0 lib/janus/strategies.rb