Paranoid mode for recoverable

This commit is contained in:
Rodrigo Flores 2011-05-20 19:41:40 -03:00
parent 09baf2091e
commit 004fe2ad12
4 changed files with 17 additions and 3 deletions

View File

@ -11,15 +11,20 @@ class Devise::PasswordsController < ApplicationController
# POST /resource/password
def create
self.resource = resource_class.send_reset_password_instructions(params[resource_name])
if resource.errors.empty?
if Devise.paranoid
set_flash_message(:notice, :send_instructions) if is_navigational_format?
respond_with resource, :location => after_sending_reset_password_instructions_path_for(resource_name)
else
respond_with_navigational(resource){ render_with_scope :new }
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
end
end
# GET /resource/password/edit?reset_password_token=abcdef
def edit
self.resource = resource_class.new

View File

@ -27,6 +27,8 @@ en:
passwords:
send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
updated: 'Your password was changed successfully. You are now signed in.'
paranoid:
send_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
confirmations:
send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
confirmed: 'Your account was successfully confirmed. You are now signed in.'

View File

@ -237,6 +237,10 @@ module Devise
@@warden_config = nil
@@warden_config_block = nil
# TODO Write a meaningful description about this attribute
mattr_accessor :paranoid
@@paranoid = false
# Default way to setup Devise. Run rails generate devise_install to create
# a fresh initializer with all configuration values.
def self.setup

View File

@ -115,6 +115,9 @@ MESSAGE
# available.
def set_flash_message(key, kind, options={}) #:nodoc:
options[:scope] = "devise.#{controller_name}"
if Devise.paranoid && controller_name == "passwords"
options[:scope] += ".paranoid"
end
options[:default] = Array(options[:default]).unshift(kind.to_sym)
options[:resource_name] = resource_name
message = I18n.t("#{resource_name}.#{kind}", options)