Module: Devise::Models::Authenticatable::ClassMethods
- Defined in:
- lib/devise/models/authenticatable.rb
Instance Method Summary collapse
- #find_first_by_auth_conditions(conditions) ⇒ Object
-
#find_for_authentication(conditions) ⇒ Object
Find first record based on conditions given (ie by the sign in form).
-
#find_or_initialize_with_error_by(attribute, value, error = :invalid) ⇒ Object
Find an initialize a record setting an error if it can’t be found.
-
#find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) ⇒ Object
Find an initialize a group of attributes based on a list of required attributes.
- #http_authenticatable?(strategy) ⇒ Boolean
- #params_authenticatable?(strategy) ⇒ Boolean
- #serialize_from_session(key, salt) ⇒ Object
- #serialize_into_session(record) ⇒ Object
Instance Method Details
#find_first_by_auth_conditions(conditions) ⇒ Object
134 135 136 |
# File 'lib/devise/models/authenticatable.rb', line 134 def find_first_by_auth_conditions(conditions) to_adapter.find_first devise_param_filter.filter(conditions) end |
#find_for_authentication(conditions) ⇒ Object
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
130 131 132 |
# File 'lib/devise/models/authenticatable.rb', line 130 def find_for_authentication(conditions) find_first_by_auth_conditions(conditions) end |
#find_or_initialize_with_error_by(attribute, value, error = :invalid) ⇒ Object
Find an initialize a record setting an error if it can’t be found.
139 140 141 |
# File 'lib/devise/models/authenticatable.rb', line 139 def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc: find_or_initialize_with_errors([attribute], { attribute => value }, error) end |
#find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) ⇒ Object
Find an initialize a group of attributes based on a list of required attributes.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/devise/models/authenticatable.rb', line 144 def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc: attributes = attributes.slice(*required_attributes) attributes.delete_if { |key, value| value.blank? } if attributes.size == required_attributes.size record = find_first_by_auth_conditions(attributes) end unless record record = new required_attributes.each do |key| value = attributes[key] record.send("#{key}=", value) record.errors.add(key, value.present? ? error : :blank) end end record end |
#http_authenticatable?(strategy) ⇒ Boolean
115 116 117 118 |
# File 'lib/devise/models/authenticatable.rb', line 115 def http_authenticatable?(strategy) http_authenticatable.is_a?(Array) ? http_authenticatable.include?(strategy) : http_authenticatable end |
#params_authenticatable?(strategy) ⇒ Boolean
110 111 112 113 |
# File 'lib/devise/models/authenticatable.rb', line 110 def params_authenticatable?(strategy) params_authenticatable.is_a?(Array) ? params_authenticatable.include?(strategy) : params_authenticatable end |
#serialize_from_session(key, salt) ⇒ Object
105 106 107 108 |
# File 'lib/devise/models/authenticatable.rb', line 105 def serialize_from_session(key, salt) record = to_adapter.get(key) record if record && record.authenticatable_salt == salt end |
#serialize_into_session(record) ⇒ Object
101 102 103 |
# File 'lib/devise/models/authenticatable.rb', line 101 def serialize_into_session(record) [record.to_key, record.authenticatable_salt] end |