Module: RailsWarden::Authentication

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_warden/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(*args) ⇒ Object

Proxy to the authenticate method on warden :api: public


46
47
48
# File 'lib/rails_warden/authentication.rb', line 46

def authenticate(*args)
  warden.authenticate(*args)
end

#authenticate!(*args) ⇒ Object

Proxy to the authenticate method on warden :api: public


52
53
54
55
56
57
58
59
60
# File 'lib/rails_warden/authentication.rb', line 52

def authenticate!(*args)
  defaults = {action: RailsWarden.unauthenticated_action}
  if args.last.is_a? Hash
    args[-1] = defaults.merge(args.last)
  else
    args << defaults
  end
  warden.authenticate!(*args)
end

#authenticated?(*args) ⇒ Boolean

Proxy to the authenticated? method on warden :api: public

Returns:

  • (Boolean)

18
19
20
# File 'lib/rails_warden/authentication.rb', line 18

def authenticated?(*args)
  warden.authenticated?(*args)
end

#login!(user, scope: :default) ⇒ Object


28
29
30
# File 'lib/rails_warden/authentication.rb', line 28

def login!(user, scope: :default)
  warden.set_user(user, scope: scope)
end

#logout!(scope: nil) ⇒ Object

Logout the current user :api: public


34
35
36
37
38
39
40
41
42
# File 'lib/rails_warden/authentication.rb', line 34

def logout!(scope: nil)
  if scope
    warden.logout(scope: scope)
    warden.clear_strategies_cache!(scope: scope)
  else
    warden.logout
    warden.clear_strategies_cache!
  end
end

#user(*args) ⇒ Object

Access the currently logged in user :api: public


24
25
26
# File 'lib/rails_warden/authentication.rb', line 24

def user(*args)
  warden.user(*args)
end

#wardenObject

The main accessor for the warden proxy instance :api: public


12
13
14
# File 'lib/rails_warden/authentication.rb', line 12

def warden
  request.env['warden']
end