1
0
Fork 0
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:
Rodrigo Flores 2011-06-22 12:33:28 -03:00
parent 40c0a7b50b
commit 6199252011
4 changed files with 26 additions and 30 deletions

View file

@ -11,19 +11,14 @@ 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 }
else
if resource.errors.empty?
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
respond_with_navigational(resource){ render_with_scope :new }
end
end
end
# GET /resource/confirmation?confirmation_token=abcdef
def show

View file

@ -12,19 +12,13 @@ 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 }
else
if resource.errors.empty?
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
respond_with_navigational(resource){ render_with_scope :new }
end
end
end
# GET /resource/password/edit?reset_password_token=abcdef

View file

@ -12,19 +12,13 @@ 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 }
else
if resource.errors.empty?
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
respond_with_navigational(resource){ render_with_scope :new }
end
end
end
# GET /resource/unlock?unlock_token=abcdef
def show

View file

@ -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.