Module: Janus::Strategies

Extended by:
ActiveSupport::Concern
Included in:
Manager
Defined in:
lib/janus.rb,
lib/janus/strategies.rb,
lib/janus/strategies/base.rb,
lib/janus/strategies/rememberable.rb,
lib/janus/strategies/token_authenticatable.rb,
lib/janus/strategies/remote_authenticatable.rb

Defined Under Namespace

Modules: ClassMethods Classes: Base, Rememberable, RemoteAuthenticatable, TokenAuthenticatable

Instance Method Summary collapse

Instance Method Details

#run_strategies(scope) ⇒ Object

Runs authentication strategies to log a user in.



6
7
8
# File 'lib/janus/strategies.rb', line 6

def run_strategies(scope)
  Janus::Manager.strategies.each { |name| break if run_strategy(name, scope) }
end

#run_strategy(name, scope) ⇒ Object

Runs a given strategy and returns true if it succeeded.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/janus/strategies.rb', line 11

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