1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

first attempt

This commit is contained in:
Andrew Dahl 2010-11-18 21:24:42 +01:00
parent 67645c68f7
commit 94c666e439
3 changed files with 15 additions and 1 deletions

View file

@ -67,6 +67,10 @@ module Devise
mattr_accessor :request_keys mattr_accessor :request_keys
@@request_keys = [] @@request_keys = []
# If authentication keys should be case-insensitive by default.
mattr_accessor :case_insensitive_keys
@@case_insensitive_keys = false
# If http authentication is enabled by default. # If http authentication is enabled by default.
mattr_accessor :http_authenticatable mattr_accessor :http_authenticatable
@@http_authenticatable = false @@http_authenticatable = false

View file

@ -77,7 +77,7 @@ module Devise
end end
module ClassMethods module ClassMethods
Devise::Models.config(self, :authentication_keys, :request_keys, :http_authenticatable, :params_authenticatable) Devise::Models.config(self, :authentication_keys, :request_keys, :case_insensitive_keys, :http_authenticatable, :params_authenticatable)
def params_authenticatable?(strategy) def params_authenticatable?(strategy)
params_authenticatable.is_a?(Array) ? params_authenticatable.is_a?(Array) ?
@ -100,6 +100,9 @@ module Devise
# end # end
# #
def find_for_authentication(conditions) def find_for_authentication(conditions)
if case_insensitive_keys
authentication_keys.each { |k| conditions[k].try(:downcase!) }
end
to_adapter.find_first(conditions) to_adapter.find_first(conditions)
end end
@ -110,6 +113,10 @@ module Devise
# Find an initialize a group of attributes based on a list of required attributes. # 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: def find_or_initialize_with_errors(required_attributes, attributes, error=:invalid) #:nodoc:
if case_insensitive_keys
authentication_keys.each { |k| attributes[k].try(:downcase!) }
end
attributes = attributes.slice(*required_attributes) attributes = attributes.slice(*required_attributes)
attributes.delete_if { |key, value| value.blank? } attributes.delete_if { |key, value| value.blank? }

View file

@ -31,6 +31,9 @@ Devise.setup do |config|
# The same considerations mentioned for authentication_keys also apply to request_keys. # The same considerations mentioned for authentication_keys also apply to request_keys.
# config.request_keys = [] # config.request_keys = []
# If authentication keys should be case-insensitive. False by default.
# config.case_insensitive_keys = false
# Tell if authentication through request.params is enabled. True by default. # Tell if authentication through request.params is enabled. True by default.
# config.params_authenticatable = true # config.params_authenticatable = true