# File lib/devise/models/authenticatable.rb, line 246 def find_first_by_auth_conditions(tainted_conditions, opts={}) to_adapter.find_first(devise_param_filter.filter(tainted_conditions).merge(opts)) end
Find first record based on conditions given (ie by the sign in form). This method is always called during an authentication process but it may be wrapped as well. For instance, database authenticatable provides a `find_for_database_authentication` that wraps a call to this method. This allows you to customize both database authenticatable or the whole authenticate stack by customize `find_for_authentication.`
Overwrite to add customized conditions, create a join, or maybe use a namedscope to filter records while authenticating. Example:
def self.find_for_authentication(tainted_conditions) find_first_by_auth_conditions(tainted_conditions, :active => true) end
Finally, notice that Devise also queries for users in other scenarios besides authentication, for example when retrieving an user to send an e-mail for password reset. In such cases, #find_for_authentication is not called.
# File lib/devise/models/authenticatable.rb, line 242 def find_for_authentication(tainted_conditions) find_first_by_auth_conditions(tainted_conditions) end
# File lib/devise/models/authenticatable.rb, line 218 def http_authenticatable?(strategy) http_authenticatable.is_a?(Array) ? http_authenticatable.include?(strategy) : http_authenticatable end
# File lib/devise/models/authenticatable.rb, line 213 def params_authenticatable?(strategy) params_authenticatable.is_a?(Array) ? params_authenticatable.include?(strategy) : params_authenticatable end
# File lib/devise/models/authenticatable.rb, line 208 def serialize_from_session(key, salt) record = to_adapter.get(key) record if record && record.authenticatable_salt == salt end
# File lib/devise/models/authenticatable.rb, line 204 def serialize_into_session(record) [record.to_key, record.authenticatable_salt] end
# File lib/devise/models/authenticatable.rb, line 279 def devise_param_filter @devise_param_filter ||= Devise::ParamFilter.new(case_insensitive_keys, strip_whitespace_keys) end
Generate a token by looping and ensuring does not already exist.
# File lib/devise/models/authenticatable.rb, line 284 def generate_token(column) loop do token = Devise.friendly_token break token unless to_adapter.find_first({ column => token }) end end