module Devise::Models::Authenticatable::ClassMethods
def devise_parameter_filter
def devise_parameter_filter @devise_parameter_filter ||= Devise::ParameterFilter.new(case_insensitive_keys, strip_whitespace_keys) end
def find_first_by_auth_conditions(tainted_conditions, opts = {})
def find_first_by_auth_conditions(tainted_conditions, opts = {}) to_adapter.find_first(devise_parameter_filter.filter(tainted_conditions).merge(opts)) end
def find_for_authentication(tainted_conditions)
an e-mail for password reset. In such cases, find_for_authentication
besides authentication, for example when retrieving a user to send
Finally, notice that Devise also queries for users in other scenarios
end
find_first_by_auth_conditions(tainted_conditions, active: true)
def self.find_for_authentication(tainted_conditions)
Example:
namedscope to filter records while authenticating.
Overwrite to add customized conditions, create a join, or maybe use a
or the whole authenticate stack by customize `find_for_authentication.`
this method. This allows you to customize both database authenticatable
provides a `find_for_database_authentication` that wraps a call to
it may be wrapped as well. For instance, database authenticatable
This method is always called during an authentication process but
Find first record based on conditions given (ie by the sign in form).
def find_for_authentication(tainted_conditions) find_first_by_auth_conditions(tainted_conditions) end
def find_or_initialize_with_error_by(attribute, value, error = :invalid) #:nodoc:
Find or 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
def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc:
Find or initialize a record with group of attributes based on a list of required attributes.
def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc: attributes.try(:permit!) attributes = attributes.to_h.with_indifferent_access .slice(*required_attributes) .delete_if { |key, value| value.blank? } if attributes.size == required_attributes.size record = find_first_by_auth_conditions(attributes) and return record end new(devise_parameter_filter.filter(attributes)).tap do |record| required_attributes.each do |key| record.errors.add(key, attributes[key].blank? ? :blank : error) end end end
def http_authenticatable?(strategy)
def http_authenticatable?(strategy) http_authenticatable.is_a?(Array) ? http_authenticatable.include?(strategy) : http_authenticatable end
def params_authenticatable?(strategy)
def params_authenticatable?(strategy) params_authenticatable.is_a?(Array) ? params_authenticatable.include?(strategy) : params_authenticatable end
def serialize_from_session(key, salt)
def serialize_from_session(key, salt) record = to_adapter.get(key) record if record && record.authenticatable_salt == salt end
def serialize_into_session(record)
def serialize_into_session(record) [record.to_key, record.authenticatable_salt] end