lib/devise/rails/routes.rb in devise-1.1.9 vs lib/devise/rails/routes.rb in devise-1.2.rc

- old
+ new

@@ -3,11 +3,10 @@ # Ensure Devise modules are included only after loading routes, because we # need devise_for mappings already declared to create filters and helpers. def finalize_with_devise! finalize_without_devise! Devise.configure_warden! - ActionController::Base.send :include, Devise::Controllers::Helpers end alias_method_chain :finalize!, :devise end class Mapper @@ -68,10 +67,17 @@ # * :controllers => the controller which should be used. All routes by default points to Devise controllers. # However, if you want them to point to custom controller, you should do: # # devise_for :users, :controllers => { :sessions => "users/sessions" } # + # * :sign_out_via => the HTTP method(s) accepted for the :sign_out action (default: :get), + # if you wish to restrict this to accept only :post or :delete requests you should do: + # + # devise_for :users, :sign_out_via => [ :post, :delete ] + # + # You need to make sure that your sign_out controls trigger a request with a matching HTTP method. + # # * :module => the namespace to find controlers. By default, devise will access devise/sessions, # devise/registrations and so on. If you want to namespace all at once, use module: # # devise_for :users, :module => "users" # @@ -83,10 +89,14 @@ # end # # Will use publisher/sessions controller instead of devise/sessions controller. You can revert # this by providing the :module option to devise_for. # + # Also pay attention that when you use a namespace it will affect all the helpers and methods for controllers + # and views. For example, using the above setup you'll end with following methods: + # current_publisher_account, authenticate_publisher_account!, pusblisher_account_signed_in, etc. + # # * :skip => tell which controller you want to skip routes from being created: # # devise_for :users, :skip => :sessions # # ==== Scoping @@ -111,23 +121,37 @@ # def self.default_url_options # { :locale => I18n.locale } # end # end # + # ==== Adding custom actions to override controllers + # + # You can pass a block to devise_for that will add any routes defined in the block to Devise's + # list of known actions. This is important if you add a custom action to a controller that + # overrides an out of the box Devise controller. + # For example: + # + # class RegistrationsController < Devise::RegistrationsController + # def update + # # do something different here + # end + # + # def deactivate + # # not a standard action + # # deactivate code here + # end + # end + # + # In order to get Devise to recognize the deactivate action, your devise_for entry should look like this, + # + # devise_for :owners, :controllers => { :registrations => "registrations" } do + # post "deactivate", :to => "registrations#deactivate", :as => "deactivate_registration" + # end + # def devise_for(*resources) options = resources.extract_options! - if as = options.delete(:as) - ActiveSupport::Deprecation.warn ":as is deprecated, please use :path instead." - options[:path] ||= as - end - - if scope = options.delete(:scope) - ActiveSupport::Deprecation.warn ":scope is deprecated, please use :singular instead." - options[:singular] ||= scope - end - options[:as] ||= @scope[:as] if @scope[:as].present? options[:module] ||= @scope[:module] if @scope[:module].present? options[:path_prefix] ||= @scope[:path] if @scope[:path].present? options[:path_names] = (@scope[:path_names] || {}).merge(options[:path_names] || {}) @@ -152,11 +176,11 @@ routes -= Array(options.delete(:skip)).map { |s| s.to_s.singularize.to_sym } devise_scope mapping.name do yield if block_given? with_devise_exclusive_scope mapping.fullpath, mapping.name do - routes.each { |mod| send(:"devise_#{mod}", mapping, mapping.controllers) } + routes.each { |mod| send("devise_#{mod}", mapping, mapping.controllers) } end end end end @@ -201,35 +225,55 @@ protected def devise_session(mapping, controllers) #:nodoc: resource :session, :only => [], :controller => controllers[:sessions], :path => "" do - get :new, :path => mapping.path_names[:sign_in], :as => "new" - post :create, :path => mapping.path_names[:sign_in] - get :destroy, :path => mapping.path_names[:sign_out], :as => "destroy" + get :new, :path => mapping.path_names[:sign_in], :as => "new" + post :create, :path => mapping.path_names[:sign_in] + match :destroy, :path => mapping.path_names[:sign_out], :as => "destroy", :via => mapping.sign_out_via end end - + def devise_password(mapping, controllers) #:nodoc: resource :password, :only => [:new, :create, :edit, :update], :path => mapping.path_names[:password], :controller => controllers[:passwords] end - + def devise_confirmation(mapping, controllers) #:nodoc: resource :confirmation, :only => [:new, :create, :show], :path => mapping.path_names[:confirmation], :controller => controllers[:confirmations] end - + def devise_unlock(mapping, controllers) #:nodoc: if mapping.to.unlock_strategy_enabled?(:email) resource :unlock, :only => [:new, :create, :show], :path => mapping.path_names[:unlock], :controller => controllers[:unlocks] end end def devise_registration(mapping, controllers) #:nodoc: - resource :registration, :only => [:new, :create, :edit, :update, :destroy], :path => mapping.path_names[:registration], - :path_names => { :new => mapping.path_names[:sign_up] }, :controller => controllers[:registrations] + path_names = { + :new => mapping.path_names[:sign_up], + :cancel => mapping.path_names[:cancel] + } + + resource :registration, :except => :show, :path => mapping.path_names[:registration], + :path_names => path_names, :controller => controllers[:registrations] do + get :cancel + end + end + + def devise_omniauth_callback(mapping, controllers) #:nodoc: + path_prefix = "/#{mapping.path}/auth" + + if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix + warn "[DEVISE] You can only add :omniauthable behavior to one model." + else + ::OmniAuth.config.path_prefix = path_prefix + end + + match "/auth/:action/callback", :action => Regexp.union(mapping.to.omniauth_providers.map(&:to_s)), + :to => controllers[:omniauth_callbacks], :as => :omniauth_callback end def with_devise_exclusive_scope(new_path, new_as) #:nodoc: old_as, old_path, old_module = @scope[:as], @scope[:path], @scope[:module] @scope[:as], @scope[:path], @scope[:module] = new_as, new_path, nil