From 8c9cf7d67164c956597fed93ae0aecd945bc3247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Tue, 24 Jan 2012 14:23:34 +0100 Subject: [PATCH] Add deprecations, update changelog. --- CHANGELOG.rdoc | 1 + .../devise/registrations_controller.rb | 60 +++++++++---------- config/locales/en.yml | 4 -- lib/devise/rails.rb | 12 ++++ 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 8f2c4b47..09ed6410 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -18,6 +18,7 @@ Notes: https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2. * Move devise/shared/_links.erb to devise/_links.erb * Devise only supports Rails 3.1 forward * Deprecated support for nested devise_for blocks + * Deprecated support to devise.registrations.reasons and devise.registrations.inactive_signed_up in favor of devise.registrations.signed_up_but_* == 2.0.0.rc diff --git a/app/controllers/devise/registrations_controller.rb b/app/controllers/devise/registrations_controller.rb index 7d7b6420..7a3786b6 100644 --- a/app/controllers/devise/registrations_controller.rb +++ b/app/controllers/devise/registrations_controller.rb @@ -18,7 +18,7 @@ class Devise::RegistrationsController < DeviseController sign_in(resource_name, resource) respond_with resource, :location => after_sign_up_path_for(resource) else - set_flash_message :notice, :"signed_up_but_#{inactive_reason(resource)}" if is_navigational_format? + set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format? expire_session_data_after_sign_in! respond_with resource, :location => after_inactive_sign_up_path_for(resource) end @@ -74,40 +74,34 @@ class Devise::RegistrationsController < DeviseController protected - # Build a devise resource passing in the session. Useful to move - # temporary session data to the newly created user. - def build_resource(hash=nil) - hash ||= params[resource_name] || {} - self.resource = resource_class.new_with_session(hash, session) - end + # Build a devise resource passing in the session. Useful to move + # temporary session data to the newly created user. + def build_resource(hash=nil) + hash ||= params[resource_name] || {} + self.resource = resource_class.new_with_session(hash, session) + end - # The path used after sign up. You need to overwrite this method - # in your own RegistrationsController. - def after_sign_up_path_for(resource) - after_sign_in_path_for(resource) - end + # The path used after sign up. You need to overwrite this method + # in your own RegistrationsController. + def after_sign_up_path_for(resource) + after_sign_in_path_for(resource) + end - # Returns the inactive reason translated. - def inactive_reason(resource) - reason = resource.inactive_message.to_s - I18n.t("devise.registrations.reasons.#{reason}", :default => reason) - end + # The path used after sign up for inactive accounts. You need to overwrite + # this method in your own RegistrationsController. + def after_inactive_sign_up_path_for(resource) + respond_to?(:root_path) ? root_path : "/" + end - # The path used after sign up for inactive accounts. You need to overwrite - # this method in your own RegistrationsController. - def after_inactive_sign_up_path_for(resource) - respond_to?(:root_path) ? root_path : "/" - end + # 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) + signed_in_root_path(resource) + end - # 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) - signed_in_root_path(resource) - end - - # Authenticates the current scope and gets the current resource from the session. - def authenticate_scope! - send(:"authenticate_#{resource_name}!", :force => true) - self.resource = send(:"current_#{resource_name}") - end + # Authenticates the current scope and gets the current resource from the session. + def authenticate_scope! + send(:"authenticate_#{resource_name}!", :force => true) + self.resource = send(:"current_#{resource_name}") + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index bd937baa..73df488c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -41,10 +41,6 @@ en: updated: 'You updated your account successfully.' update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address." destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.' - reasons: - inactive: 'inactive' - unconfirmed: 'unconfirmed' - locked: 'locked' unlocks: send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.' unlocked: 'Your account has been unlocked successfully. Please sign in to continue.' diff --git a/lib/devise/rails.rb b/lib/devise/rails.rb index e7aa3f40..91bfc555 100644 --- a/lib/devise/rails.rb +++ b/lib/devise/rails.rb @@ -80,6 +80,18 @@ module Devise "your Devise models (if they don't have one already).\n" end end + + config.after_initialize do + if I18n.t(:"devise.registrations.reasons", :default => {}).present? + warn "\n[DEVISE] devise.registrations.reasons in yml files is deprecated, " \ + "please use devise.registrations.signed_up_but_REASON instead.\n" + end + + if I18n.t(:"devise.registrations.inactive_signed_up", :default => "").present? + warn "\n[DEVISE] devise.registrations.inactive_signed_up in yml files is deprecated, " \ + "please use devise.registrations.signed_up_but_inactive instead.\n" + end + end end end end