Module: Devise::Models::LdapAuthenticatable::ClassMethods

Defined in:
lib/devise_ldap_multiple/model.rb

Instance Method Summary collapse

Instance Method Details

#find_for_ldap_authentication(attributes = {}) ⇒ Object

Find a user for ldap authentication.



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/devise_ldap_multiple/model.rb', line 98

def find_for_ldap_authentication(attributes={})
  auth_key = self.authentication_keys.first
  return nil unless attributes[auth_key].present?

  auth_key_value = (self.case_insensitive_keys || []).include?(auth_key) ? attributes[auth_key].downcase : attributes[auth_key]
 auth_key_value = (self.strip_whitespace_keys || []).include?(auth_key) ? auth_key_value.strip : auth_key_value

  resource = where(auth_key => auth_key_value).first

  if resource.blank?
    resource = new
    resource[auth_key] = auth_key_value
    resource.password = attributes[:password]
  end

  if Devise::LDAP::Adapter.user_creatable?(self.authentication_keys.first, self.name.downcase) && resource.new_record? && resource.valid_ldap_authentication?(attributes[:password])
    resource.ldap_before_save if resource.respond_to?(:ldap_before_save)
    resource.save!
  end

  resource
end

#update_with_password(resource) ⇒ Object



121
122
123
# File 'lib/devise_ldap_multiple/model.rb', line 121

def update_with_password(resource)
  puts "UPDATE_WITH_PASSWORD: #{resource.inspect}"
end