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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/devise_ldap_authenticatable/model.rb', line 70

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

  # resource = find_for_ldap_authentication(conditions)
  resource = where(auth_key => attributes[auth_key]).first
            
  if (resource.blank? and ::Devise.ldap_create_user)
    resource = new
    resource[auth_key] = attributes[auth_key]
    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



94
95
96
# File 'lib/devise_ldap_authenticatable/model.rb', line 94

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