diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index da89ea56..712e140f 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,3 +1,11 @@ +* deprecations + * Renamed mail_sender to mailer_sender + +* enhancements + * skip_before_filter added in Devise controllers + * Use home_or_root_path on require_no_authentication as well + * Added devise_controller?, useful to select or reject filters in ApplicationController + == 0.4.1 * bug fix diff --git a/README.rdoc b/README.rdoc index 0d0762e7..d34e65a6 100644 --- a/README.rdoc +++ b/README.rdoc @@ -154,7 +154,7 @@ After signing in a user, confirming it's account or updating it's password, devi You also need to setup default url options for the mailer, if you are using confirmable or recoverable. Here's is the configuration for development: DeviseMailer.sender = "no-reply@yourapp.com" - ActionMailer::Base.default_url_options = { :host => 'localhost:3000' } + config.action_mailer.default_url_options = { :host => 'localhost:3000' } == Tidying up diff --git a/generators/devise/templates/README b/generators/devise/templates/README index bb46514d..c748d5fa 100644 --- a/generators/devise/templates/README +++ b/generators/devise/templates/README @@ -7,12 +7,13 @@ Some setup you must do manually if you haven't yet: config.action_mailer.default_url_options = { :host => 'localhost:3000' } -It's a Rails required configuration. -In production it must be the actual host your application is deployed to. +It's a Rails required configuration. In production it must be the actual host your application is deployed to. -2. Setup default sender for mails.In config/environment.rb: +2. Setup default sender for mails. In config/environment.rb: - Notifier.sender = "test@example.com" + DeviseMailer.sender = "test@example.com" + +You can also configure this value by running script/generate devise_install and setting config.mailer_sender, 3. Ensure you have defined root_url to *something* in your config/routes.rb: diff --git a/generators/devise_install/templates/devise.rb b/generators/devise_install/templates/devise.rb index e910d4a5..08c4dfe2 100644 --- a/generators/devise_install/templates/devise.rb +++ b/generators/devise_install/templates/devise.rb @@ -16,13 +16,13 @@ Devise.setup do |config| # config.remember_for = 2.weeks # Configure the e-mail address which will be shown in DeviseMailer. - # config.mail_sender = "foo.bar@yourapp.com" + # config.mailer_sender = "foo.bar@yourapp.com" # If you want to use other strategies, that are not (yet) supported by Devise, # you can configure them inside the config.warden block. The example below # allows you to setup OAuth, using http://github.com/roman/warden_oauth # - # config.manager do |manager| + # config.warden do |manager| # manager.oauth(:twitter) do |twitter| # twitter.consumer_secret = # twitter.consumer_key = diff --git a/lib/devise.rb b/lib/devise.rb index d1a4d0ff..dc11a9d1 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -31,11 +31,16 @@ module Devise yield self end - # Sets the sender in DeviseMailer. - def mail_sender=(value) + def mail_sender=(value) #:nodoc: + ActiveSupport::Deprecation.warn "Devise.mail_sender= is deprecated, use Devise.mailer_sender instead" DeviseMailer.sender = value end - alias :sender= :mail_sender= + + # Sets the sender in DeviseMailer. + def mailer_sender=(value) + DeviseMailer.sender = value + end + alias :sender= :mailer_sender= # Sets warden configuration using a block that will be invoked on warden # initialization. diff --git a/lib/devise/controllers/filters.rb b/lib/devise/controllers/filters.rb index c95c87d6..8157b400 100644 --- a/lib/devise/controllers/filters.rb +++ b/lib/devise/controllers/filters.rb @@ -6,7 +6,7 @@ module Devise def self.included(base) base.class_eval do - helper_method :warden, :signed_in?, + helper_method :warden, :signed_in?, :devise_controller?, *Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten end end @@ -16,6 +16,15 @@ module Devise request.env['warden'] end + # Return true if it's a devise_controller. false to all controllers unless + # the controllers defined inside devise. Useful if you want to apply a before + # filter to all controller, except the ones in devise: + # + # before_filter :my_filter, :unless => { |c| c.devise_controller? } + def devise_controller? + false + end + # Attempts to authenticate the given scope by running authentication hooks, # but does not redirect in case of failures. def authenticate(scope) diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 7437f164..c28c8959 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -7,9 +7,10 @@ module Devise def self.included(base) base.class_eval do - helper_method :resource, :resource_name, :resource_class, :devise_mapping - hide_action :resource, :resource_name, :resource_class, :devise_mapping + helper_method :resource, :resource_name, :resource_class, :devise_mapping, :devise_controller? + hide_action :resource, :resource_name, :resource_class, :devise_mapping, :devise_controller? + skip_before_filter *Devise.mappings.keys.map { |m| :"authenticate_#{m}!" } before_filter :is_devise_resource? end end @@ -34,6 +35,11 @@ module Devise @devise_mapping ||= Devise::Mapping.find_by_path(request.path) end + # Overwrites devise_controller? to return true + def devise_controller? + true + end + protected # Redirects to stored uri before signing in or the default path and clear @@ -91,7 +97,7 @@ module Devise # Example: # before_filter :require_no_authentication, :only => :new def require_no_authentication - redirect_to root_path if warden.authenticated?(resource_name) + redirect_to home_or_root_path if warden.authenticated?(resource_name) end # Sets the flash message with :key, using I18n. By default you are able diff --git a/test/controllers/filters_test.rb b/test/controllers/filters_test.rb index 15139607..aff45bb6 100644 --- a/test/controllers/filters_test.rb +++ b/test/controllers/filters_test.rb @@ -87,4 +87,8 @@ class ControllerAuthenticableTest < ActionController::TestCase @mock_warden.expects(:set_user).with(user = mock, :scope => :user).returns(true) @controller.sign_in(:user, user) end + + test 'is not a devise controller' do + assert_not @controller.devise_controller? + end end diff --git a/test/controllers/helpers_test.rb b/test/controllers/helpers_test.rb index 02756525..66ff85e9 100644 --- a/test/controllers/helpers_test.rb +++ b/test/controllers/helpers_test.rb @@ -43,9 +43,13 @@ class HelpersTest < ActionController::TestCase end test 'require no authentication tests current mapping' do - @controller.expects(:resource_name).returns(:user) + @controller.expects(:resource_name).returns(:user).twice @mock_warden.expects(:authenticated?).with(:user).returns(true) @controller.expects(:redirect_to).with(root_path) @controller.send :require_no_authentication end + + test 'is a devise controller' do + assert @controller.devise_controller? + end end diff --git a/test/devise_test.rb b/test/devise_test.rb index 4b7c7ba1..baf6f787 100644 --- a/test/devise_test.rb +++ b/test/devise_test.rb @@ -27,7 +27,7 @@ class DeviseTest < ActiveSupport::TestCase test 'DeviseMailer.sender can be configured through Devise' do swap DeviseMailer, :sender => "foo@bar" do assert_equal "foo@bar", DeviseMailer.sender - Devise.mail_sender = "bar@foo" + Devise.mailer_sender = "bar@foo" assert_equal "bar@foo", DeviseMailer.sender end end diff --git a/test/integration/authenticatable_test.rb b/test/integration/authenticatable_test.rb index f58ecc39..11a8200c 100644 --- a/test/integration/authenticatable_test.rb +++ b/test/integration/authenticatable_test.rb @@ -114,7 +114,7 @@ class AuthenticationTest < ActionController::IntegrationTest get new_admin_session_path assert_response :redirect - assert_redirected_to root_path + assert_redirected_to admin_root_path assert warden.authenticated?(:admin) end