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

Separate redirects and flash messages in navigational_formats and flashing_formats

This commit is contained in:
Kaworu 2013-11-01 21:47:40 +01:00
parent 9eb0768cb9
commit c87809a0f5
10 changed files with 26 additions and 10 deletions

View file

@ -20,7 +20,7 @@ class Devise::ConfirmationsController < DeviseController
self.resource = resource_class.confirm_by_token(params[:confirmation_token])
if resource.errors.empty?
set_flash_message(:notice, :confirmed) if is_navigational_format?
set_flash_message(:notice, :confirmed) if is_flashing_format?
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }

View file

@ -32,7 +32,7 @@ class Devise::PasswordsController < DeviseController
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
set_flash_message(:notice, flash_message) if is_navigational_format?
set_flash_message(:notice, flash_message) if is_flashing_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_resetting_password_path_for(resource)
else

View file

@ -14,11 +14,11 @@ class Devise::RegistrationsController < DeviseController
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
set_flash_message :notice, :signed_up if is_flashing_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
@ -41,7 +41,7 @@ class Devise::RegistrationsController < DeviseController
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
if update_resource(resource, account_update_params)
if is_navigational_format?
if is_flashing_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
@ -58,7 +58,7 @@ class Devise::RegistrationsController < DeviseController
def destroy
resource.destroy
Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
set_flash_message :notice, :destroyed if is_navigational_format?
set_flash_message :notice, :destroyed if is_flashing_format?
respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
end

View file

@ -13,7 +13,7 @@ class Devise::SessionsController < DeviseController
# POST /resource/sign_in
def create
self.resource = warden.authenticate!(auth_options)
set_flash_message(:notice, :signed_in) if is_navigational_format?
set_flash_message(:notice, :signed_in) if is_flashing_format?
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_in_path_for(resource)
end
@ -22,7 +22,7 @@ class Devise::SessionsController < DeviseController
def destroy
redirect_path = after_sign_out_path_for(resource_name)
signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))
set_flash_message :notice, :signed_out if signed_out && is_navigational_format?
set_flash_message :notice, :signed_out if signed_out && is_flashing_format?
# We actually need to hardcode this as Rails default responder doesn't
# support returning empty response on GET request

View file

@ -22,7 +22,7 @@ class Devise::UnlocksController < DeviseController
self.resource = resource_class.unlock_access_by_token(params[:unlock_token])
if resource.errors.empty?
set_flash_message :notice, :unlocked if is_navigational_format?
set_flash_message :notice, :unlocked if is_flashing_format?
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
else
respond_with_navigational(resource.errors, :status => :unprocessable_entity){ render :new }

View file

@ -123,7 +123,7 @@ MESSAGE
end
if notice
set_flash_message :notice, notice if is_navigational_format?
set_flash_message :notice, notice if is_flashing_format?
true
end
end

View file

@ -209,6 +209,10 @@ module Devise
mattr_accessor :navigational_formats
@@navigational_formats = ["*/*", :html]
# Which formats should display flash messages.
mattr_accessor :flashing_formats
@@flashing_formats = nil
# When set to true, signing out a user signs out all other scopes.
mattr_accessor :sign_out_all_scopes
@@sign_out_all_scopes = true

View file

@ -291,6 +291,10 @@ module Devise
Devise.navigational_formats.include?(request_format)
end
def is_flashing_format?
(Devise.flashing_formats || Devise.navigational_formats).include?(request_format)
end
private
def expire_devise_cached_variables!

View file

@ -221,6 +221,10 @@ Devise.setup do |config|
# The "*/*" below is required to match Internet Explorer requests.
# config.navigational_formats = ['*/*', :html]
# Lists the formats that should display flash messages. Inherits
# navigational_formats if falsy
# config.flashing_formats = nil
# The default HTTP method used to sign out a resource. Default is :delete.
config.sign_out_via = :delete

View file

@ -162,6 +162,10 @@ Devise.setup do |config|
# should add them to the navigational formats lists. Default is [:html]
# config.navigational_formats = [:html, :iphone]
# Lists the formats that should display flash messages. Inherits
# navigational_formats if falsy
# config.flashing_formats = nil
# The default HTTP method used to sign out a resource. Default is :get.
# config.sign_out_via = :get