Get rid of deprecated code
This commit is contained in:
parent
7aa93a3ecb
commit
32f20dddd6
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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 = {}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue