lib/devise.rb in devise-4.0.3 vs lib/devise.rb in devise-4.1.0

- old
+ new

@@ -51,16 +51,10 @@ NO_INPUT = [] # True values used to check params TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'] - # Track the configs that user explicit changed the default value. It is - # helpfull to not warn users about default values changing when they willing - # changed. - mattr_accessor :app_set_configs - @@app_set_configs = Set.new - # Secret key used by the key generator mattr_accessor :secret_key @@secret_key = nil # Custom domain or key for cookies. Not set by default @@ -86,24 +80,13 @@ # Keys that should be case-insensitive. mattr_accessor :case_insensitive_keys @@case_insensitive_keys = [:email] # Keys that should have whitespace stripped. - # TODO: 4.1 Do: @@strip_whitespace_keys = [:email] - mattr_reader :strip_whitespace_keys - @@strip_whitespace_keys = [] + mattr_accessor :strip_whitespace_keys + @@strip_whitespace_keys = [:email] - def self.strip_whitespace_keys=(strip_whitespace_keys) - app_set_configs << :strip_whitespace_keys - @@strip_whitespace_keys = strip_whitespace_keys - end - - def strip_whitespace_keys=(strip_whitespace_keys) - app_set_configs << :strip_whitespace_keys - @@strip_whitespace_keys = strip_whitespace_keys - end - # If http authentication is enabled by default. mattr_accessor :http_authenticatable @@http_authenticatable = false # If http headers should be returned for ajax requests. True by default. @@ -116,27 +99,16 @@ # The realm used in Http Basic Authentication. mattr_accessor :http_authentication_realm @@http_authentication_realm = "Application" - # Email regex used to validate email formats. It simply asserts that - # an one (and only one) @ exists in the given string. This is mainly - # to give user feedback and not to assert the e-mail validity. - # TODO: 4.1 Do: @@email_regexp = [/\A[^@\s]+@[^@\s]+\z/] - mattr_reader :email_regexp - @@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/ + # Email regex used to validate email formats. It asserts that there are no + # @ symbols or whitespaces in either the localpart or the domain, and that + # there is a single @ symbol separating the localpart and the domain. + mattr_accessor :email_regexp + @@email_regexp = /\A[^@\s]+@[^@\s]+\z/ - def self.email_regexp=(email_regexp) - app_set_configs << :email_regexp - @@email_regexp = email_regexp - end - - def email_regexp=(email_regexp) - app_set_configs << :email_regexp - @@email_regexp = email_regexp - end - # Range validation for password length mattr_accessor :password_length @@password_length = 6..128 # The time the user will be remembered without asking for credentials again. @@ -163,25 +135,13 @@ # Defines which key will be used when confirming an account. mattr_accessor :confirmation_keys @@confirmation_keys = [:email] # Defines if email should be reconfirmable. - # False by default for backwards compatibility. - # TODO: 4.1 Do: @@reconfirmable = true - mattr_reader :reconfirmable - @@reconfirmable = false + mattr_accessor :reconfirmable + @@reconfirmable = true - def self.reconfirmable=(reconfirmable) - app_set_configs << :reconfirmable - @@reconfirmable = reconfirmable - end - - def reconfirmable=(reconfirmable) - app_set_configs << :reconfirmable - @@reconfirmable = reconfirmable - end - # Time interval to timeout the user session without activity. mattr_accessor :timeout_in @@timeout_in = 30.minutes # Used to hash the password. Please generate one with rake secret. @@ -238,47 +198,25 @@ # Address which sends Devise e-mails. mattr_accessor :mailer_sender @@mailer_sender = nil # Skip session storage for the following strategies - # TODO: 4.1 Do: @@skip_session_storage = [:http_auth] - mattr_reader :skip_session_storage - @@skip_session_storage = [] + mattr_accessor :skip_session_storage + @@skip_session_storage = [:http_auth] - def self.skip_session_storage=(skip_session_storage) - app_set_configs << :skip_session_storage - @@skip_session_storage = skip_session_storage - end - - def skip_session_storage=(skip_session_storage) - app_set_configs << :skip_session_storage - @@skip_session_storage = skip_session_storage - end - # Which formats should be treated as navigational. mattr_accessor :navigational_formats @@navigational_formats = ["*/*", :html] # When set to true, signing out a user signs out all other scopes. mattr_accessor :sign_out_all_scopes @@sign_out_all_scopes = true # The default method used while signing out - # TODO: 4.1 Do: @@sign_out_via = :delete - mattr_reader :sign_out_via - @@sign_out_via = :get + mattr_accessor :sign_out_via + @@sign_out_via = :delete - def self.sign_out_via=(sign_out_via) - app_set_configs << :sign_out_via - @@sign_out_via = sign_out_via - end - - def sign_out_via=(sign_out_via) - app_set_configs << :sign_out_via - @@sign_out_via = sign_out_via - end - # The parent controller all Devise controllers inherits from. # Defaults to ApplicationController. This should be set early # in the initialization process and should be set to a string. mattr_accessor :parent_controller @@parent_controller = "ApplicationController" @@ -338,38 +276,12 @@ # Default way to set up Devise. Run rails generate devise_install to create # a fresh initializer with all configuration values. def self.setup yield self - - warn_default_config_changed(:email_regexp, '/\A[^@\s]+@([^@\s]+\.)+[^@\W]+\z/', '/\A[^@\s]+@[^@\s]+\z/') - warn_default_config_changed(:reconfirmable, 'false', 'true') - warn_default_config_changed(:sign_out_via, ':get', ':delete') - warn_default_config_changed(:skip_session_storage, '[]', '[:http_auth]') - warn_default_config_changed(:strip_whitespace_keys, '[]', '[:email]') end - def self.warn_default_config_changed(config, current_default, new_default) - unless app_set_configs.include?(config) - warn = <<-MESSAGE.strip_heredoc - [Devise] config.#{config} will have a new default on Devise 4.1 - To keep the current behavior please set in your config/initializers/devise.rb the following: - - Devise.setup do |config| - config.#{config} = #{current_default} - end - - If you want to use the new default: - - Devise.setup do |config| - config.#{config} = #{new_default} - end - MESSAGE - ActiveSupport::Deprecation.warn(warn) - end - end - class Getter def initialize name @name = name end @@ -541,13 +453,10 @@ warden_config.serialize_into_session(mapping.name) do |record| mapping.to.serialize_into_session(record) end - warden_config.serialize_from_session(mapping.name) do |key| - # Previous versions contained an additional entry at the beginning of - # key with the record's class name. - args = key[-2, 2] + warden_config.serialize_from_session(mapping.name) do |args| mapping.to.serialize_from_session(*args) end end @@warden_config_blocks.map { |block| block.call Devise.warden_config }