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

Defined in:
lib/devise_ldap_authenticatable/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_with_ldap(attributes = {}) ⇒ Object

Authenticate a user based on configured attribute keys. Returns the authenticated user if it’s valid or nil.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/devise_ldap_authenticatable/model.rb', line 76

def authenticate_with_ldap(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]

  # resource = find_for_ldap_authentication(conditions)
  resource = where(auth_key => auth_key_value).first

  if (resource.blank? and ::Devise.ldap_create_user)
    resource = new
    resource[auth_key] = auth_key_value
    resource.password = attributes[:password]
  end

  if resource.try(:valid_ldap_authentication?, attributes[:password])
    if resource.new_record?
      resource.ldap_before_save if resource.respond_to?(:ldap_before_save)
      resource.save
    end
    return resource
  else
    return nil
  end
end

#update_with_password(resource) ⇒ Object



102
103
104
# File 'lib/devise_ldap_authenticatable/model.rb', line 102

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