Permalink
Browse files

after_sign_in_path_for now redirects to session[scope_return_to] if a…

…ny value is stored in it
  • Loading branch information...
1 parent f3aa5e4 commit bba6562dccbb18a727e92c39668546084410ea75 @josevalim josevalim committed Sep 29, 2011
View
@@ -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
@@ -41,7 +41,7 @@ def after_resending_confirmation_instructions_path_for(resource_name)
# 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
@@ -35,7 +35,7 @@ def update
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
@@ -17,7 +17,7 @@ def create
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 @@ def after_sign_up_path_for(resource)
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 @@ def after_inactive_sign_up_path_for(resource)
# 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.
@@ -15,7 +15,7 @@ def create
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
@@ -27,7 +27,7 @@ def show
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
@@ -166,12 +166,21 @@ def stored_location_for(resource_or_scope)
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 @@ def stored_location_for(resource_or_scope)
# 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 @@ def sign_in_and_redirect(resource_or_scope, *args)
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

0 comments on commit bba6562

Please sign in to comment.