Class: Devise::Strategies::LdapAuthenticatable

Inherits:
Authenticatable
  • Object
show all
Defined in:
lib/devise_ldap_authenticatable/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object

Tests whether the returned resource exists in the database and the credentials are valid. If the resource is in the database and the credentials are valid, the user is authenticated. Otherwise failure messages are returned indicating whether the resource is not found in the database or the credentials are invalid.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/devise_ldap_authenticatable/strategy.rb', line 12

def authenticate!
  resource = mapping.to.find_for_ldap_authentication(authentication_hash.merge(:password => password))

  return fail(:invalid) unless resource

  if resource.persisted?
    if validate(resource) { resource.valid_ldap_authentication?(password) }
      remember_me(resource)
      resource.after_ldap_authentication
      success!(resource)
    else
      return fail(:invalid) # Invalid credentials
    end
  end

  if resource.new_record?
    if validate(resource) { resource.valid_ldap_authentication?(password) }
      return fail(:not_found_in_database) # Valid credentials
    else
      return fail(:invalid) # Invalid credentials
    end
  end
end