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.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/devise_ldap_authenticatable/model.rb', line 79

def authenticate_with_ldap(attributes={}) 
	
	@login_with = ::Devise.authentication_keys.first
	return nil unless attributes[@login_with].present? 
	
	# Get the value to be compared within the database against the @login_with field 
	# According to User Specified details
	# Application Specific Change
	 
	 = attributes[@login_with]
	resource = new
	resource[@login_with] = attributes[@login_with]
	resource.password = attributes[:password]
						
	if resource.try(:valid_ldap_authentication?, attributes[:password])
		 = resource.attribute_to_compare
		resource = where(@login_with => ).first
		
		if (resource.blank? and ::Devise.ldap_create_user)
			resource = new
			resource[@login_with] = attributes[@login_with]
			resource.password = attributes[:password]
		end
		unless resource.blank?
          resource[@login_with] = attributes[@login_with]						
          resource.update_persistant_attributes
          DeviseLdapAuthenticatable::Logger.send("Updating persistant attributes") unless resource.new_record?
          resource.save
        end
		return resource
	else
		return nil
	end

end

#update_with_password(resource) ⇒ Object



115
116
117
# File 'lib/devise_ldap_authenticatable/model.rb', line 115

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