lib/devise/rails/routes.rb in devise-2.2.3 vs lib/devise/rails/routes.rb in devise-2.2.4

- old
+ new

@@ -248,47 +248,39 @@ # authenticate(:admin) do # resources :users # end # # authenticate :user, lambda {|u| u.role == "admin"} do - # root :to => "admin/dashboard#show" + # root :to => "admin/dashboard#show", :as => :user_root # end # def authenticate(scope=nil, block=nil) - constraint = lambda do |request| - request.env["warden"].authenticate!(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope))) - end - - constraints(constraint) do + constraints_for(:authenticate!, scope, block) do yield end end # Allow you to route based on whether a scope is authenticated. You # can optionally specify which scope and a block. The block accepts # a model and allows extra constraints to be done on the instance. # # authenticated :admin do - # root :to => 'admin/dashboard#show' + # root :to => 'admin/dashboard#show', :as => :admin_root # end # # authenticated do - # root :to => 'dashboard#show' + # root :to => 'dashboard#show', :as => :authenticated_root # end # # authenticated :user, lambda {|u| u.role == "admin"} do - # root :to => "admin/dashboard#show" + # root :to => "admin/dashboard#show", :as => :user_root # end # # root :to => 'landing#show' # def authenticated(scope=nil, block=nil) - constraint = lambda do |request| - request.env["warden"].authenticate?(:scope => scope) && (block.nil? || block.call(request.env["warden"].user(scope))) - end - - constraints(constraint) do + constraints_for(:authenticate?, scope, block) do yield end end # Allow you to route based on whether a scope is *not* authenticated. @@ -327,11 +319,11 @@ # Also be aware of that 'devise_scope' and 'as' use the singular form of the # noun where other devise route commands expect the plural form. This would be a # good and working example. # # devise_scope :user do - # match "/some/route" => "some_devise_controller" + # get "/some/route" => "some_devise_controller" # end # devise_for :users # # Notice and be aware of the differences above between :user and :users def devise_scope(scope) @@ -399,16 +391,18 @@ providers = Regexp.union(mapping.to.omniauth_providers.map(&:to_s)) match "#{path_prefix}/:provider", :constraints => { :provider => providers }, :to => "#{controllers[:omniauth_callbacks]}#passthru", - :as => :omniauth_authorize + :as => :omniauth_authorize, + :via => [:get, :post] match "#{path_prefix}/:action/callback", :constraints => { :action => providers }, :to => controllers[:omniauth_callbacks], - :as => :omniauth_callback + :as => :omniauth_callback, + :via => [:get, :post] ensure @scope[:path] = path end DEVISE_SCOPE_KEYS = [:as, :path, :module, :constraints, :defaults, :options] @@ -422,9 +416,20 @@ @scope.merge!(new) yield ensure @scope.merge!(old) + end + + def constraints_for(method_to_apply, scope=nil, block=nil) + constraint = lambda do |request| + request.env['warden'].send(method_to_apply, :scope => scope) && + (block.nil? || block.call(request.env["warden"].user(scope))) + end + + constraints(constraint) do + yield + end end def set_omniauth_path_prefix!(path_prefix) #:nodoc: if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix raise "Wrong OmniAuth configuration. If you are getting this exception, it means that either:\n\n" \