lib/devise/models/authenticatable.rb in devise-1.2.rc2 vs lib/devise/models/authenticatable.rb in devise-1.2.0

- old
+ new

@@ -22,23 +22,23 @@ # It also accepts an array specifying the strategies that should allow http. # # * +params_authenticatable+: if this model allows authentication through request params. By default true. # It also accepts an array specifying the strategies that should allow params authentication. # - # == Active? + # == active_for_authentication? # # Before authenticating a user and in each request, Devise checks if your model is active by - # calling model.active?. This method is overwriten by other devise modules. For instance, - # :confirmable overwrites .active? to only return true if your model was confirmed. + # calling model.active_for_authentication?. This method is overwriten by other devise modules. For instance, + # :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed. # # You overwrite this method yourself, but if you do, don't forget to call super: # - # def active? + # def active_for_authentication? # super && special_condition_is_valid? # end # - # Whenever active? returns false, Devise asks the reason why your model is inactive using + # Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using # the inactive_message method. You can overwrite it as well: # # def inactive_message # special_condition_is_valid? ? super : :special_condition_is_not_valid # end @@ -53,24 +53,36 @@ # Check if the current object is valid for authentication. This method and # find_for_authentication are the methods used in a Warden::Strategy to check # if a model should be signed in or not. # - # However, you should not overwrite this method, you should overwrite active? and - # inactive_message instead. + # However, you should not overwrite this method, you should overwrite active_for_authentication? + # and inactive_message instead. def valid_for_authentication? - if active? + if active_for_authentication? block_given? ? yield : true else inactive_message end end def active? - true + ActiveSupport::Deprecation.warn "[DEVISE] active? is deprecated, please use active_for_authentication? instead.", caller + active_for_authentication? end + def active_for_authentication? + my_methods = self.class.instance_methods(false) + if my_methods.include?("active?") || my_methods.include?(:active?) + ActiveSupport::Deprecation.warn "[DEVISE] Overriding active? is deprecated to avoid conflicts. " \ + "Please use active_for_authentication? instead.", caller + active? + else + true + end + end + def inactive_message :inactive end def authenticatable_salt @@ -99,22 +111,22 @@ # super # end # def find_for_authentication(conditions) filter_auth_params(conditions) - case_insensitive_keys.each { |k| conditions[k].try(:downcase!) } + (case_insensitive_keys || []).each { |k| conditions[k].try(:downcase!) } to_adapter.find_first(conditions) end # Find an initialize a record setting an error if it can't be found. def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc: find_or_initialize_with_errors([attribute], { attribute => value }, error) end # Find an initialize a group of attributes based on a list of required attributes. def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc: - case_insensitive_keys.each { |k| attributes[k].try(:downcase!) } + (case_insensitive_keys || []).each { |k| attributes[k].try(:downcase!) } attributes = attributes.slice(*required_attributes) attributes.delete_if { |key, value| value.blank? } if attributes.size == required_attributes.size @@ -138,10 +150,10 @@ # Force keys to be string to avoid injection on mongoid related database. def filter_auth_params(conditions) conditions.each do |k, v| conditions[k] = v.to_s - end + end if conditions.is_a?(Hash) end # Generate a token by looping and ensuring does not already exist. def generate_token(column) loop do \ No newline at end of file