From 32f20dddd654d5dfbd99c821fe2918c191959b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Sun, 6 May 2012 13:13:53 +0200 Subject: [PATCH] Get rid of deprecated code --- CHANGELOG.rdoc | 2 + lib/devise.rb | 41 ++----- lib/devise/controllers/helpers.rb | 5 - lib/devise/models.rb | 8 +- lib/devise/models/authenticatable.rb | 4 +- lib/devise/orm/active_record.rb | 43 +------- lib/devise/orm/mongoid.rb | 30 +---- lib/devise/rails.rb | 59 +--------- lib/devise/schema.rb | 109 ------------------- lib/generators/templates/devise.rb | 8 -- test/rails_app/config/initializers/devise.rb | 7 -- 11 files changed, 20 insertions(+), 296 deletions(-) delete mode 100644 lib/devise/schema.rb diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 3cde680e..fc67b5ea 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -5,6 +5,8 @@ * deprecations * Deprecations warnings added on Devise 2.0 are now removed with their features + * use_salt_as_remember_token and apply_schema does not have any effect since 2.0 and are now deprecated + * valid_for_authentication? must now return a boolean * bug fix * `/users/sign_in` doesn't choke on protected attributes used to select sign in scope (by @Paymium) diff --git a/lib/devise.rb b/lib/devise.rb index ecd192e8..f4aec231 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -78,14 +78,12 @@ module Devise @@request_keys = [] # Keys that should be case-insensitive. - # False by default for backwards compatibility. mattr_accessor :case_insensitive_keys - @@case_insensitive_keys = false + @@case_insensitive_keys = [ :email ] # Keys that should have whitespace stripped. - # False by default for backwards compatibility. mattr_accessor :strip_whitespace_keys - @@strip_whitespace_keys = false + @@strip_whitespace_keys = [] # If http authentication is enabled by default. mattr_accessor :http_authenticatable @@ -182,9 +180,8 @@ module Devise @@reset_password_keys = [ :email ] # Time interval you can reset your password with a reset password key - # Nil by default for backwards compatibility. mattr_accessor :reset_password_within - @@reset_password_within = nil + @@reset_password_within = 6.hours # The default scope which is used by warden. mattr_accessor :default_scope @@ -226,36 +223,14 @@ module Devise mattr_accessor :router_name @@router_name = nil - # DEPRECATED CONFIG + # DEPRECATION - # If true, uses salt as remember token and does not create it in the database. - # By default is false for backwards compatibility. - mattr_accessor :use_salt_as_remember_token - @@use_salt_as_remember_token = false - - # Tells if devise should apply the schema in ORMs where devise declaration - # and schema belongs to the same class (as Datamapper and Mongoid). - mattr_accessor :apply_schema - @@apply_schema = true - - def self.remember_across_browsers=(value) - warn "\n[DEVISE] Devise.remember_across_browsers is deprecated and has no effect. Please remove it.\n" + def self.use_salt_as_remember_token=(value) + warn "\n[DEVISE] Devise.use_salt_as_remember_token is deprecated and has no effect. Please remove it.\n" end - def self.confirm_within=(value) - warn "\n[DEVISE] Devise.confirm_within= is deprecated. Please set Devise.allow_unconfirmed_access_for= instead.\n" - Devise.allow_unconfirmed_access_for = value - end - - def self.cookie_options=(value) - warn "\n[DEVISE] Devise.cookie_options= is deprecated. Please set Devise.rememberable_options= instead.\n" - Devise.rememberable_options = value - end - - def self.stateless_token=(value) - warn "\n[DEVISE] Devise.stateless_token= is deprecated. Please append :token_auth to Devise.skip_session_storage " \ - "instead, for example: Devise.skip_session_storage << :token_auth\n" - Devise.skip_session_storage << :token_auth + def self.apply_schema=(value) + warn "\n[DEVISE] Devise.apply_schema is deprecated and has no effect. Please remove it.\n" end # PRIVATE CONFIGURATION diff --git a/lib/devise/controllers/helpers.rb b/lib/devise/controllers/helpers.rb index 0f324846..abbccaeb 100644 --- a/lib/devise/controllers/helpers.rb +++ b/lib/devise/controllers/helpers.rb @@ -237,11 +237,6 @@ module Devise redirect_to after_sign_in_path_for(resource) end - def redirect_location(scope, resource) #:nodoc: - ActiveSupport::Deprecation.warn "redirect_location in Devise is deprecated. Please use after_sign_in_path_for instead.", caller - after_sign_in_path_for(resource) - end - def expire_session_data_after_sign_in! session.keys.grep(/^devise\./).each { |k| session.delete(k) } end diff --git a/lib/devise/models.rb b/lib/devise/models.rb index f06a6776..222cffe2 100644 --- a/lib/devise/models.rb +++ b/lib/devise/models.rb @@ -60,7 +60,9 @@ module Devise failed_attributes << field unless instance.respond_to?(field) end else - ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). Devise uses required_fields to warn developers of any missing fields in their models. Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields." + ActiveSupport::Deprecation.warn "The module #{mod} doesn't implement self.required_fields(klass). " \ + "Devise uses required_fields to warn developers of any missing fields in their models. " \ + "Please implement #{mod}.required_fields(klass) that returns an array of symbols with the required fields." end end @@ -110,8 +112,8 @@ module Devise end end - # The hook which is called inside devise. So your ORM can include devise - # compatibility stuff. + # The hook which is called inside devise. + # So your ORM can include devise compatibility stuff. def devise_modules_hook! yield end diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index d6481b7f..9b6f6968 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -102,11 +102,11 @@ module Devise end def downcase_keys - (self.class.case_insensitive_keys || []).each { |k| self[k].try(:downcase!) } + self.class.case_insensitive_keys.each { |k| self[k].try(:downcase!) } end def strip_whitespace - (self.class.strip_whitespace_keys || []).each { |k| self[k].try(:strip!) } + self.class.strip_whitespace_keys.each { |k| self[k].try(:strip!) } end array = %w(serializable_hash) diff --git a/lib/devise/orm/active_record.rb b/lib/devise/orm/active_record.rb index a583b5d8..52343d4f 100644 --- a/lib/devise/orm/active_record.rb +++ b/lib/devise/orm/active_record.rb @@ -1,44 +1,3 @@ require 'orm_adapter/adapters/active_record' -module Devise - module Orm - # This module contains some helpers and handle schema (migrations): - # - # create_table :accounts do |t| - # t.database_authenticatable - # t.confirmable - # t.recoverable - # t.rememberable - # t.trackable - # t.lockable - # t.timestamps - # end - # - # However this method does not add indexes. If you need them, here is the declaration: - # - # add_index "accounts", ["email"], :name => "email", :unique => true - # add_index "accounts", ["confirmation_token"], :name => "confirmation_token", :unique => true - # add_index "accounts", ["reset_password_token"], :name => "reset_password_token", :unique => true - # - module ActiveRecord - module Schema - include Devise::Schema - - # Tell how to apply schema methods. - def apply_devise_schema(name, type, options={}) - @__devise_warning_raised ||= begin - $stderr.puts "\n[DEVISE] You are using t.database_authenticatable and others in your migration " \ - "and this feature is deprecated. Please simply use Rails helpers instead as mentioned here:\n" \ - "https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n\n" - true - end - column name, type.to_s.downcase.to_sym, options - end - end - end - end -end - -ActiveRecord::Base.extend Devise::Models -ActiveRecord::ConnectionAdapters::Table.send :include, Devise::Orm::ActiveRecord::Schema -ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Orm::ActiveRecord::Schema \ No newline at end of file +ActiveRecord::Base.extend Devise::Models \ No newline at end of file diff --git a/lib/devise/orm/mongoid.rb b/lib/devise/orm/mongoid.rb index e5a1c971..858a9156 100644 --- a/lib/devise/orm/mongoid.rb +++ b/lib/devise/orm/mongoid.rb @@ -1,31 +1,3 @@ require 'orm_adapter/adapters/mongoid' -module Devise - module Orm - module Mongoid - module Hook - def devise_modules_hook! - extend Schema - yield - return unless Devise.apply_schema - devise_modules.each { |m| send(m) if respond_to?(m, true) } - end - end - - module Schema - include Devise::Schema - - # Tell how to apply schema methods - def apply_devise_schema(name, type, options={}) - type = Time if type == DateTime - field name, { :type => type }.merge!(options) - end - end - end - end -end - -Mongoid::Document::ClassMethods.class_eval do - include Devise::Models - include Devise::Orm::Mongoid::Hook -end +Mongoid::Document::ClassMethods.send :include, Devise::Models \ No newline at end of file diff --git a/lib/devise/rails.rb b/lib/devise/rails.rb index 98d51b2b..24a5f924 100644 --- a/lib/devise/rails.rb +++ b/lib/devise/rails.rb @@ -43,69 +43,12 @@ module Devise end initializer "devise.fix_routes_proxy_missing_respond_to_bug" do - # We can get rid of this once we support Rails > 3.2 + # We can get rid of this once we support only Rails > 3.2 ActionDispatch::Routing::RoutesProxy.class_eval do def respond_to?(method, include_private = false) super || routes.url_helpers.respond_to?(method) end end end - - initializer "devise.deprecations" do - unless defined?(Rails::Generators) - if Devise.case_insensitive_keys == false - warn "\n[DEVISE] Devise.case_insensitive_keys is false which is no longer " \ - "supported. Recent Devise versions automatically downcase the e-mail before " \ - "saving it to the database but your app isn't using this feature. You can solve " \ - "this issue by either:\n\n" \ - "1) Setting config.case_insensitive_keys = [:email] in your Devise initializer and " \ - "running a migration that will downcase all emails already in the database;\n\n" \ - "2) Setting config.case_insensitive_keys = [] (so nothing will be downcased) and " \ - "making sure you are not using Devise :validatable (since validatable assumes case" \ - "insensitivity)\n" - end - - if Devise.apply_schema && defined?(Mongoid) - warn "\n[DEVISE] Devise.apply_schema is true. This means Devise was " \ - "automatically configuring your DB. This no longer happens. You should " \ - "set Devise.apply_schema to false and manually set the fields used by Devise as shown here: " \ - "https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0-migration-schema-style\n" - end - - # TODO: Deprecate the true value of this option as well - if Devise.use_salt_as_remember_token == false - warn "\n[DEVISE] Devise.use_salt_as_remember_token is false which is no longer " \ - "supported. Devise now only uses the salt as remember token and the remember_token " \ - "column can be removed from your models.\n" - end - - if Devise.reset_password_within.nil? - warn "\n[DEVISE] Devise.reset_password_within is nil. Please set this value to " \ - "an interval (for example, 6.hours) and add a reset_password_sent_at field to " \ - "your Devise models (if they don't have one already).\n" - end - end - - config.after_initialize do - example = <<-YAML -en: - devise: - registrations: - signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.' - signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.' - signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.' - YAML - - 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. The default values are:\n\n#{example}\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_REASON instead. The default values are:\n\n#{example}\n" - end - end - end end end diff --git a/lib/devise/schema.rb b/lib/devise/schema.rb deleted file mode 100644 index 560efde5..00000000 --- a/lib/devise/schema.rb +++ /dev/null @@ -1,109 +0,0 @@ -module Devise - # Holds devise schema information. To use it, just include its methods - # and overwrite the apply_schema method. - module Schema - - # Creates encrypted_password, and email when it is used as an authentication - # key (default). - # - # == Options - # * :null - When true, allow columns to be null. - # * :default - Set to "" when :null is false, unless overridden. - # - # == Notes - # For Datamapper compatibility, we explicitly hardcode the limit for the - # encrypter password field in 128 characters. - def database_authenticatable(options={}) - null = options[:null] || false - default = options.key?(:default) ? options[:default] : ("" if null == false) - include_email = !respond_to?(:authentication_keys) || self.authentication_keys.include?(:email) - - apply_devise_schema :email, String, :null => null, :default => default if include_email - apply_devise_schema :encrypted_password, String, :null => null, :default => default, :limit => 128 - end - - # Creates password salt for encryption support when using encryptors other - # than the database_authenticable default of bcrypt. - def encryptable - apply_devise_schema :password_salt, String - end - - # Creates authentication_token. - def token_authenticatable - apply_devise_schema :authentication_token, String - end - - # Creates confirmation_token, confirmed_at and confirmation_sent_at. - def confirmable - apply_devise_schema :confirmation_token, String - apply_devise_schema :confirmed_at, DateTime - apply_devise_schema :confirmation_sent_at, DateTime - end - - # Creates unconfirmed_email - def reconfirmable - apply_devise_schema :unconfirmed_email, String - end - - # Creates reset_password_token and reset_password_sent_at. - # - # == Options - # * :reset_within - When true, adds a column that reset passwords within some date - def recoverable(options={}) - use_within = options.fetch(:reset_within, Devise.reset_password_within.present?) - apply_devise_schema :reset_password_token, String - apply_devise_schema :reset_password_sent_at, DateTime if use_within - end - - # Creates remember_token and remember_created_at. - # - # == Options - # * :use_salt - When true, does not create a remember_token and use password_salt instead. - def rememberable(options={}) - use_salt = options.fetch(:use_salt, Devise.use_salt_as_remember_token) - apply_devise_schema :remember_token, String unless use_salt - apply_devise_schema :remember_created_at, DateTime - end - - # Creates sign_in_count, current_sign_in_at, last_sign_in_at, - # current_sign_in_ip, last_sign_in_ip. - def trackable - apply_devise_schema :sign_in_count, Integer, :default => 0 - apply_devise_schema :current_sign_in_at, DateTime - apply_devise_schema :last_sign_in_at, DateTime - apply_devise_schema :current_sign_in_ip, String - apply_devise_schema :last_sign_in_ip, String - end - - # Creates failed_attempts, unlock_token and locked_at depending on the options given. - # - # == Options - # * :unlock_strategy - The strategy used for unlock. Can be :time, :email, :both (default), :none. - # If :email or :both, creates a unlock_token field. - # * :lock_strategy - The strategy used for locking. Can be :failed_attempts (default) or :none. - def lockable(options={}) - unlock_strategy = options[:unlock_strategy] - unlock_strategy ||= self.unlock_strategy if respond_to?(:unlock_strategy) - unlock_strategy ||= :both - - lock_strategy = options[:lock_strategy] - lock_strategy ||= self.lock_strategy if respond_to?(:lock_strategy) - lock_strategy ||= :failed_attempts - - if lock_strategy == :failed_attempts - apply_devise_schema :failed_attempts, Integer, :default => 0 - end - - if [:both, :email].include?(unlock_strategy) - apply_devise_schema :unlock_token, String - end - - apply_devise_schema :locked_at, DateTime - end - - # Overwrite with specific modification to create your own schema. - def apply_devise_schema(name, type, options={}) - raise NotImplementedError - end - end -end diff --git a/lib/generators/templates/devise.rb b/lib/generators/templates/devise.rb index af25f032..42c1f321 100644 --- a/lib/generators/templates/devise.rb +++ b/lib/generators/templates/devise.rb @@ -9,9 +9,6 @@ Devise.setup do |config| # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" - # Automatically apply schema changes in tableless databases - config.apply_schema = false - # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -111,11 +108,6 @@ Devise.setup do |config| # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false - # This configures your application to use the salt as the remember token. - # Leave this set to true - this option was kept for backwards compatibility - # and will be removed in some future releases. - config.use_salt_as_remember_token = true - # Options to be passed to the created cookie. For instance, you can set # :secure => true in order to force SSL only cookies. # config.rememberable_options = {} diff --git a/test/rails_app/config/initializers/devise.rb b/test/rails_app/config/initializers/devise.rb index ccd0db6a..96987a8f 100644 --- a/test/rails_app/config/initializers/devise.rb +++ b/test/rails_app/config/initializers/devise.rb @@ -12,9 +12,6 @@ Devise.setup do |config| # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" - # Disable apply schema - config.apply_schema = false - # ==> ORM configuration # Load and configure the ORM. Supports :active_record (default) and # :mongoid (bson_ext recommended) by default. Other ORMs may be @@ -87,10 +84,6 @@ Devise.setup do |config| # If true, extends the user's remember period when remembered via cookie. # config.extend_remember_period = false - # If true, uses the password salt as remember token. This should be turned - # to false if you are not using database authenticatable. - config.use_salt_as_remember_token = true - # ==> Configuration for :validatable # Range for password length. Default is 6..128. # config.password_length = 6..128