Skip to content

Instantly share code, notes, and snippets.

@kadru
Created January 25, 2019 21:30
Show Gist options
  • Save kadru/aab517da14d8773e824ac23a2dd4faeb to your computer and use it in GitHub Desktop.
Save kadru/aab517da14d8773e824ac23a2dd4faeb to your computer and use it in GitHub Desktop.
require 'net/ldap'
module Ldap
LDAP_SERVER_IP = 'buzon.uach.mx'.freeze
#LDAP_USERNAME = 'ldap_username'
#LDAP_PASSWORD = 'ldap_password'
#Obtiene el nombre mediante su cuenta de usuario
def self.get_name_for_email(username,password,email)
initializ "uid=#{username},ou=People,o=uach.mx,o=uach.mx", password
base_ldap = "OU=People, o=uach.mx, o=uach.mx"
if @ldap.bind
@ldap.search(:base => base_ldap, :filter => Net::LDAP::Filter.eq( "mail", email ),
:return_result => true).first.cn.first
else
return nil
end
end
#Obtiene el numero de empleado mediante su cuenta de usuario
def self.get_employee_number_for_email(username,password,email)
initializ "uid=#{username},ou=People,o=uach.mx,o=uach.mx", password
base_ldap = "OU=People, o=uach.mx, o=uach.mx"
if @ldap.bind
@ldap.search(:base => base_ldap, :filter => Net::LDAP::Filter.eq( "mail", email ),
:return_result => true).first.employeeNumber.first
else
return nil
end
end
protected
def auth?(username, password)
initializ "uid=#{username},ou=People,o=uach.mx,o=uach.mx", password
@ldap.bind
end
def initializ(username, password)
@ldap = Net::LDAP.new
@ldap.host = LDAP_SERVER_IP
@ldap.auth username, password
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment