mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Refactored paranoid mode actions for it to appear once
This commit is contained in:
parent
40c0a7b50b
commit
6199252011
4 changed files with 26 additions and 30 deletions
|
@ -11,17 +11,12 @@ class Devise::ConfirmationsController < ApplicationController
|
|||
def create
|
||||
self.resource = resource_class.send_confirmation_instructions(params[resource_name])
|
||||
|
||||
if Devise.paranoid
|
||||
set_flash_message(:notice, :send_paranoid_instructions) if is_navigational_format?
|
||||
resource.errors.clear
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
|
||||
if successful_and_sane?(resource)
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
|
||||
else
|
||||
if resource.errors.empty?
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => after_resending_confirmation_instructions_path_for(resource_name)
|
||||
else
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,17 +12,11 @@ class Devise::PasswordsController < ApplicationController
|
|||
def create
|
||||
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
|
||||
|
||||
if Devise.paranoid
|
||||
set_flash_message(:notice, :send_paranoid_instructions) if is_navigational_format?
|
||||
resource.errors.clear
|
||||
respond_with_navigational(resource) { render_with_scope :new }
|
||||
if successful_and_sane?(resource)
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => new_session_path(resource_name)
|
||||
else
|
||||
if resource.errors.empty?
|
||||
set_flash_message(:notice, :send_instructions) if is_navigational_format?
|
||||
respond_with resource, :location => new_session_path(resource_name)
|
||||
else
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,17 +12,11 @@ class Devise::UnlocksController < ApplicationController
|
|||
def create
|
||||
self.resource = resource_class.send_unlock_instructions(params[resource_name])
|
||||
|
||||
if Devise.paranoid
|
||||
set_flash_message :notice, :send_paranoid_instructions if is_navigational_format?
|
||||
resource.errors.clear
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
if successful_and_sane?(resource)
|
||||
set_flash_message :notice, :send_instructions if is_navigational_format?
|
||||
respond_with resource, :location => new_session_path(resource_name)
|
||||
else
|
||||
if resource.errors.empty?
|
||||
set_flash_message :notice, :send_instructions if is_navigational_format?
|
||||
respond_with resource, :location => new_session_path(resource_name)
|
||||
else
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
respond_with_navigational(resource){ render_with_scope :new }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -99,6 +99,19 @@ MESSAGE
|
|||
end
|
||||
end
|
||||
|
||||
# Helper for use to validate if an resource is errorless. If we are on paranoid mode, we always should assume it is
|
||||
# and return false.
|
||||
|
||||
def successful_and_sane?(resource)
|
||||
if Devise.paranoid
|
||||
set_flash_message :notice, :send_paranoid_instructions if is_navigational_format?
|
||||
resource.errors.clear
|
||||
false
|
||||
else
|
||||
resource.errors.empty?
|
||||
end
|
||||
end
|
||||
|
||||
# Sets the flash message with :key, using I18n. By default you are able
|
||||
# to setup your messages using specific resource scope, and if no one is
|
||||
# found we look to default scope.
|
||||
|
|
Loading…
Reference in a new issue