lib/sorcery/model/adapters/mongoid.rb in sorcery-0.6.1 vs lib/sorcery/model/adapters/mongoid.rb in sorcery-0.7.0
- old
+ new
@@ -13,11 +13,15 @@
end
end
module ClassMethods
def find_by_credentials(credentials)
- where(sorcery_config.username_attribute_name => credentials[0]).first
+ @sorcery_config.username_attribute_names.each do |attribute|
+ @user = where(attribute => credentials[0]).first
+ break if @user
+ end
+ @user
end
def find_by_provider_and_uid(provider, uid)
@user_klass ||= ::Sorcery::Controller::Config.user_class.to_s.constantize
where(@user_klass.sorcery_config.provider_attribute_name => provider, @user_klass.sorcery_config.provider_uid_attribute_name => uid).first
@@ -34,10 +38,11 @@
def find_by_remember_me_token(token)
where(sorcery_config.remember_me_token_attribute_name => token).first
end
def find_by_username(username)
- where(sorcery_config.username_attribute_name => username).first
+ query = sorcery_config.username_attribute_names.map {|name| {name => username}}
+ where(query).first
end
def transaction(&blk)
tap(&blk)
end