cartodb-4.42/app/models/carto/ldap/entry.rb

39 lines
660 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
# See http://www.rubydoc.info/gems/net-ldap/0.11
require 'net/ldap'
class Carto::Ldap::Entry
def initialize(ldap_entry, ldap_configuration)
@entry = ldap_entry
@configuration = ldap_configuration
end
def user_id
extract_field(@configuration.user_id_field)
end
def cartodb_user_id
Carto::Ldap::Manager.sanitize_for_cartodb(user_id)
end
def username
extract_field(@configuration.username_field)
end
def email
extract_field(@configuration.email_field)
end
def configuration
@configuration
end
private
def extract_field(field)
value = @entry[field]
value.nil? ? nil : value.first
end
end