Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow options to be passed to authenticate_user!

  • Loading branch information...
commit 98acc84111456c92d74905f19cd21bd2d6abae21 1 parent 261c01d
@josevalim josevalim authored
View
2  app/controllers/devise/registrations_controller.rb
@@ -114,7 +114,7 @@ def after_update_path_for(resource)
# Authenticates the current scope and gets the current resource from the session.
def authenticate_scope!
- send(:"authenticate_#{resource_name}!", true)
+ send(:"authenticate_#{resource_name}!", :force => true)
self.resource = send(:"current_#{resource_name}")
end
end
View
15 lib/devise/controllers/helpers.rb
@@ -36,8 +36,14 @@ def self.define_helpers(mapping) #:nodoc:
mapping = mapping.name
class_eval <<-METHODS, __FILE__, __LINE__ + 1
- def authenticate_#{mapping}!(force = false)
- warden.authenticate!(:scope => :#{mapping}) if !devise_controller? || force
+ def authenticate_#{mapping}!(opts={})
+ if !opts.is_a?(Hash)
+ opts = { :force => opts }
+ ActiveSupport::Deprecation.warn "Passing a boolean to authenticate_#{mapping}! " \
+ "is deprecated, please use :force => \#{opts[:force]} instead", caller
+ end
+ opts[:scope] = :#{mapping}
+ warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
end
def #{mapping}_signed_in?
@@ -72,6 +78,11 @@ def devise_controller?
false
end
+ # Tell warden that params authentication is allowed for that specific page.
+ def allow_params_authentication!
+ request.env["devise.allow_params_authentication"] = true
+ end
+
# Return true if the given scope is signed in session. If no scope given, return
# true if any scope is signed in. Does not run authentication hooks.
def signed_in?(scope=nil)
View
5 test/controllers/helpers_test.rb
@@ -45,6 +45,11 @@ def setup
@controller.authenticate_user!
end
+ test 'proxy authenticate_user! options to authenticate with user scope' do
+ @mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
+ @controller.authenticate_user!(:recall => "foo")
+ end
+
test 'proxy authenticate_admin! to authenticate with admin scope' do
@mock_warden.expects(:authenticate!).with(:scope => :admin)
@controller.authenticate_admin!
Please sign in to comment.
Something went wrong with that request. Please try again.