Module: Devise::Controllers::Filters
- Defined in:
- lib/devise/controllers/filters.rb
Overview
Those filters are convenience methods added to ApplicationController to deal with Warden.
Class Method Summary collapse
Instance Method Summary collapse
-
#authenticate(scope) ⇒ Object
Attempts to authenticate the given scope by running authentication hooks, but does not redirect in case of failures.
-
#authenticate!(scope) ⇒ Object
Attempts to authenticate the given scope by running authentication hooks, redirecting in case of failures.
-
#sign_in(scope, resource) ⇒ Object
Set the warden user with the scope, signing in the resource automatically, without running hooks.
-
#sign_out(scope, *args) ⇒ Object
Sign out based on scope.
-
#signed_in?(scope) ⇒ Boolean
Check if the given scope is signed in session, without running authentication hooks.
-
#warden ⇒ Object
The main accessor for the warden proxy instance.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/devise/controllers/filters.rb', line 7 def self.included(base) base.class_eval do helper_method :warden, :signed_in?, *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten end end |
Instance Method Details
#authenticate(scope) ⇒ Object
Attempts to authenticate the given scope by running authentication hooks, but does not redirect in case of failures.
21 22 23 |
# File 'lib/devise/controllers/filters.rb', line 21 def authenticate(scope) warden.authenticate(:scope => scope) end |
#authenticate!(scope) ⇒ Object
Attempts to authenticate the given scope by running authentication hooks, redirecting in case of failures.
27 28 29 |
# File 'lib/devise/controllers/filters.rb', line 27 def authenticate!(scope) warden.authenticate!(:scope => scope) end |
#sign_in(scope, resource) ⇒ Object
Set the warden user with the scope, signing in the resource automatically, without running hooks.
39 40 41 |
# File 'lib/devise/controllers/filters.rb', line 39 def sign_in(scope, resource) warden.set_user(resource, :scope => scope) end |
#sign_out(scope, *args) ⇒ Object
Sign out based on scope.
44 45 46 47 48 |
# File 'lib/devise/controllers/filters.rb', line 44 def sign_out(scope, *args) warden.user(scope) # Without loading user here, before_logout hook is not called warden.raw_session.inspect # Without this inspect here. The session does not clear. warden.logout(scope, *args) end |
#signed_in?(scope) ⇒ Boolean
Check if the given scope is signed in session, without running authentication hooks.
33 34 35 |
# File 'lib/devise/controllers/filters.rb', line 33 def signed_in?(scope) warden.authenticated?(scope) end |
#warden ⇒ Object
The main accessor for the warden proxy instance
15 16 17 |
# File 'lib/devise/controllers/filters.rb', line 15 def warden request.env['warden'] end |