1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

after_sign_in_path_for now redirects to session[scope_return_to] if any value is stored in it

This commit is contained in:
José Valim 2011-09-29 13:07:13 +02:00
parent f3aa5e40fb
commit bba6562dcc
7 changed files with 31 additions and 30 deletions

View file

@ -4,6 +4,10 @@
* Allow idempotent API requests
* Fix bug where logs did not show 401 as status code
* deprecation
* redirect_location is deprecated, please use after_sign_in_path_for
* after_sign_in_path_for now redirects to session[scope_return_to] if any value is stored in it
== 1.4.7
* bug fix

View file

@ -41,7 +41,7 @@ class Devise::ConfirmationsController < ApplicationController
# The path used after confirmation.
def after_confirmation_path_for(resource_name, resource)
redirect_location(resource_name, resource)
after_sign_in_path_for(resource)
end
end

View file

@ -35,7 +35,7 @@ class Devise::PasswordsController < ApplicationController
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
else
respond_with_navigational(resource){ render_with_scope :edit }
end

View file

@ -17,7 +17,7 @@ class Devise::RegistrationsController < ApplicationController
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :inactive_signed_up, :reason => inactive_reason(resource) if is_navigational_format?
expire_session_data_after_sign_in!
@ -83,11 +83,6 @@ class Devise::RegistrationsController < ApplicationController
after_sign_in_path_for(resource)
end
# Overwrite redirect_for_sign_in so it takes uses after_sign_up_path_for.
def redirect_location(scope, resource)
stored_location_for(scope) || after_sign_up_path_for(resource)
end
# Returns the inactive reason translated.
def inactive_reason(resource)
reason = resource.inactive_message.to_s
@ -103,13 +98,7 @@ class Devise::RegistrationsController < ApplicationController
# The default url to be used after updating a resource. You need to overwrite
# this method in your own RegistrationsController.
def after_update_path_for(resource)
if defined?(super)
ActiveSupport::Deprecation.warn "Defining after_update_path_for in ApplicationController " <<
"is deprecated. Please add a RegistrationsController to your application and define it there."
super
else
after_sign_in_path_for(resource)
end
signed_in_root_path(resource)
end
# Authenticates the current scope and gets the current resource from the session.

View file

@ -15,7 +15,7 @@ class Devise::SessionsController < ApplicationController
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
respond_with resource, :location => redirect_location(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
# DELETE /resource/sign_out

View file

@ -27,7 +27,7 @@ class Devise::UnlocksController < ApplicationController
if resource.errors.empty?
set_flash_message :notice, :unlocked if is_navigational_format?
sign_in(resource_name, resource)
respond_with_navigational(resource){ redirect_to redirect_location(resource_name, resource) }
respond_with_navigational(resource){ redirect_to after_sign_in_path_for(resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render_with_scope :new }
end

View file

@ -166,12 +166,21 @@ module Devise
session.delete("#{scope}_return_to")
end
# The scope root url to be used when he's signed in. By default, it first
# tries to find a resource_root_path, otherwise it uses the root_path.
def signed_in_root_path(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
home_path = "#{scope}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
end
# The default url to be used after signing in. This is used by all Devise
# controllers and you can overwrite it in your ApplicationController to
# provide a custom hook for a custom resource.
#
# By default, it first tries to find a resource_root_path, otherwise it
# uses the root path. For a user scope, you can define the default url in
# By default, it first tries to find a valid resource_return_to key in the
# session, then it fallbacks to resource_root_path, otherwise it uses the
# root path. For a user scope, you can define the default url in
# the following way:
#
# map.user_root '/users', :controller => 'users' # creates user_root_path
@ -180,22 +189,20 @@ module Devise
# user.root :controller => 'users' # creates user_root_path
# end
#
#
# If the resource root path is not defined, root_path is used. However,
# if this default is not enough, you can customize it, for example:
#
# def after_sign_in_path_for(resource)
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# super
# end
# store_location_for(resource) ||
# if resource.is_a?(User) && resource.can_publish?
# publisher_url
# else
# signed_in_root_path(resource)
# end
# end
#
def after_sign_in_path_for(resource_or_scope)
scope = Devise::Mapping.find_scope!(resource_or_scope)
home_path = "#{scope}_root_path"
respond_to?(home_path, true) ? send(home_path) : root_path
stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)
end
# Method used by sessions controller to sign out a user. You can overwrite
@ -216,11 +223,12 @@ module Devise
scope = Devise::Mapping.find_scope!(resource_or_scope)
resource = args.last || resource_or_scope
sign_in(scope, resource, options)
redirect_to redirect_location(scope, resource)
redirect_to after_sign_in_path_for(resource)
end
def redirect_location(scope, resource) #:nodoc:
stored_location_for(scope) || after_sign_in_path_for(resource)
ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller
after_sign_in_path_for(resource)
end
# Sign out a user and tries to redirect to the url specified by