Class: Trestle::Auth::Backends::Warden

Inherits:
Base
  • Object
show all
Defined in:
lib/trestle/auth/backends/warden.rb

Direct Known Subclasses

Devise

Instance Attribute Summary

Attributes inherited from Base

#controller, #cookies, #request, #session

Instance Method Summary collapse

Methods inherited from Base

#initialize, #previous_location, #store_location

Constructor Details

This class inherits a constructor from Trestle::Auth::Backends::Base

Instance Method Details

#authenticateObject

Authenticates the user using Warden.



11
12
13
# File 'lib/trestle/auth/backends/warden.rb', line 11

def authenticate
  warden.authenticate(scope: scope)
end

#authenticate!Object

Authenticates a user from a login form request.



6
7
8
# File 'lib/trestle/auth/backends/warden.rb', line 6

def authenticate!
  authenticate
end

#logged_in?Boolean

Checks if there is a logged in user.

Returns:

  • (Boolean)


16
17
18
# File 'lib/trestle/auth/backends/warden.rb', line 16

def logged_in?
  warden.authenticated?(scope)
end

#login!(user) ⇒ Object

Stores the given user as logged in.



26
27
28
# File 'lib/trestle/auth/backends/warden.rb', line 26

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

#logout!Object

Logs out the current user.



31
32
33
34
35
36
37
38
39
# File 'lib/trestle/auth/backends/warden.rb', line 31

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

#scopeObject

Set the login params scope from configuration, which is also used as the Warden scope.



42
43
44
# File 'lib/trestle/auth/backends/warden.rb', line 42

def scope
  Trestle.config.auth.warden.scope
end

#userObject

Returns the current logged in user.



21
22
23
# File 'lib/trestle/auth/backends/warden.rb', line 21

def user
  warden.user(scope)
end