mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Merge branch 'master' of git@github.com:plataformatec/devise
This commit is contained in:
commit
c06d9ad7ae
11 changed files with 54 additions and 17 deletions
|
@ -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
|
== 0.4.1
|
||||||
|
|
||||||
* bug fix
|
* bug fix
|
||||||
|
|
|
@ -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:
|
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"
|
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
|
== Tidying up
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,13 @@ Some setup you must do manually if you haven't yet:
|
||||||
|
|
||||||
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
|
||||||
|
|
||||||
It's a Rails required configuration.
|
It's a Rails required configuration. In production it must be the actual host your application is deployed to.
|
||||||
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:
|
3. Ensure you have defined root_url to *something* in your config/routes.rb:
|
||||||
|
|
||||||
|
|
|
@ -16,13 +16,13 @@ Devise.setup do |config|
|
||||||
# config.remember_for = 2.weeks
|
# config.remember_for = 2.weeks
|
||||||
|
|
||||||
# Configure the e-mail address which will be shown in DeviseMailer.
|
# 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,
|
# 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
|
# you can configure them inside the config.warden block. The example below
|
||||||
# allows you to setup OAuth, using http://github.com/roman/warden_oauth
|
# 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|
|
# manager.oauth(:twitter) do |twitter|
|
||||||
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
# twitter.consumer_secret = <YOUR CONSUMER SECRET>
|
||||||
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
# twitter.consumer_key = <YOUR CONSUMER KEY>
|
||||||
|
|
|
@ -31,11 +31,16 @@ module Devise
|
||||||
yield self
|
yield self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the sender in DeviseMailer.
|
def mail_sender=(value) #:nodoc:
|
||||||
def mail_sender=(value)
|
ActiveSupport::Deprecation.warn "Devise.mail_sender= is deprecated, use Devise.mailer_sender instead"
|
||||||
DeviseMailer.sender = value
|
DeviseMailer.sender = value
|
||||||
end
|
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
|
# Sets warden configuration using a block that will be invoked on warden
|
||||||
# initialization.
|
# initialization.
|
||||||
|
|
|
@ -6,7 +6,7 @@ module Devise
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
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
|
*Devise.mappings.keys.map { |m| [:"current_#{m}", :"#{m}_signed_in?"] }.flatten
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,15 @@ module Devise
|
||||||
request.env['warden']
|
request.env['warden']
|
||||||
end
|
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,
|
# Attempts to authenticate the given scope by running authentication hooks,
|
||||||
# but does not redirect in case of failures.
|
# but does not redirect in case of failures.
|
||||||
def authenticate(scope)
|
def authenticate(scope)
|
||||||
|
|
|
@ -7,9 +7,10 @@ module Devise
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
helper_method :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
|
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?
|
before_filter :is_devise_resource?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -34,6 +35,11 @@ module Devise
|
||||||
@devise_mapping ||= Devise::Mapping.find_by_path(request.path)
|
@devise_mapping ||= Devise::Mapping.find_by_path(request.path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Overwrites devise_controller? to return true
|
||||||
|
def devise_controller?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# Redirects to stored uri before signing in or the default path and clear
|
# Redirects to stored uri before signing in or the default path and clear
|
||||||
|
@ -91,7 +97,7 @@ module Devise
|
||||||
# Example:
|
# Example:
|
||||||
# before_filter :require_no_authentication, :only => :new
|
# before_filter :require_no_authentication, :only => :new
|
||||||
def require_no_authentication
|
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
|
end
|
||||||
|
|
||||||
# Sets the flash message with :key, using I18n. By default you are able
|
# Sets the flash message with :key, using I18n. By default you are able
|
||||||
|
|
|
@ -87,4 +87,8 @@ class ControllerAuthenticableTest < ActionController::TestCase
|
||||||
@mock_warden.expects(:set_user).with(user = mock, :scope => :user).returns(true)
|
@mock_warden.expects(:set_user).with(user = mock, :scope => :user).returns(true)
|
||||||
@controller.sign_in(:user, user)
|
@controller.sign_in(:user, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'is not a devise controller' do
|
||||||
|
assert_not @controller.devise_controller?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,9 +43,13 @@ class HelpersTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'require no authentication tests current mapping' do
|
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)
|
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
||||||
@controller.expects(:redirect_to).with(root_path)
|
@controller.expects(:redirect_to).with(root_path)
|
||||||
@controller.send :require_no_authentication
|
@controller.send :require_no_authentication
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'is a devise controller' do
|
||||||
|
assert @controller.devise_controller?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ class DeviseTest < ActiveSupport::TestCase
|
||||||
test 'DeviseMailer.sender can be configured through Devise' do
|
test 'DeviseMailer.sender can be configured through Devise' do
|
||||||
swap DeviseMailer, :sender => "foo@bar" do
|
swap DeviseMailer, :sender => "foo@bar" do
|
||||||
assert_equal "foo@bar", DeviseMailer.sender
|
assert_equal "foo@bar", DeviseMailer.sender
|
||||||
Devise.mail_sender = "bar@foo"
|
Devise.mailer_sender = "bar@foo"
|
||||||
assert_equal "bar@foo", DeviseMailer.sender
|
assert_equal "bar@foo", DeviseMailer.sender
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -114,7 +114,7 @@ class AuthenticationTest < ActionController::IntegrationTest
|
||||||
get new_admin_session_path
|
get new_admin_session_path
|
||||||
|
|
||||||
assert_response :redirect
|
assert_response :redirect
|
||||||
assert_redirected_to root_path
|
assert_redirected_to admin_root_path
|
||||||
assert warden.authenticated?(:admin)
|
assert warden.authenticated?(:admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue