module Devise::Models::Authenticatable::ClassMethods

Public Instance Methods

find_first_by_auth_conditions(conditions) click to toggle source
# File lib/devise/models/authenticatable.rb, line 139
def find_first_by_auth_conditions(conditions)
  to_adapter.find_first devise_param_filter.filter(conditions)
end
find_for_authentication(conditions) click to toggle source

Find first record based on conditions given (ie by the sign in form). Overwrite to add customized conditions, create a join, or maybe use a namedscope to filter records while authenticating. Example:

def self.find_for_authentication(conditions={})
  conditions[:active] = true
  super
end
# File lib/devise/models/authenticatable.rb, line 135
def find_for_authentication(conditions)
  find_first_by_auth_conditions(conditions)
end
http_authenticatable?(strategy) click to toggle source
# File lib/devise/models/authenticatable.rb, line 120
def http_authenticatable?(strategy)
  http_authenticatable.is_a?(Array) ?
    http_authenticatable.include?(strategy) : http_authenticatable
end
params_authenticatable?(strategy) click to toggle source
# File lib/devise/models/authenticatable.rb, line 115
def params_authenticatable?(strategy)
  params_authenticatable.is_a?(Array) ?
    params_authenticatable.include?(strategy) : params_authenticatable
end
serialize_from_session(key, salt) click to toggle source
# File lib/devise/models/authenticatable.rb, line 110
def serialize_from_session(key, salt)
  record = to_adapter.get(key)
  record if record && record.authenticatable_salt == salt
end
serialize_into_session(record) click to toggle source
# File lib/devise/models/authenticatable.rb, line 106
def serialize_into_session(record)
  [record.to_key, record.authenticatable_salt]
end

Protected Instance Methods

devise_param_filter() click to toggle source
# File lib/devise/models/authenticatable.rb, line 172
def devise_param_filter
  @devise_param_filter ||= Devise::ParamFilter.new(case_insensitive_keys, strip_whitespace_keys)
end
generate_token(column) click to toggle source

Generate a token by looping and ensuring does not already exist.

# File lib/devise/models/authenticatable.rb, line 177
def generate_token(column)
  loop do
    token = Devise.friendly_token
    break token unless to_adapter.find_first({ column => token })
  end
end