liquid_feedback_frontend
view env/ldap/get_member_entry.lua @ 1829:4d27edb80e89
Fix error when creating new user
| author | bsw | 
|---|---|
| date | Thu Feb 03 12:17:08 2022 +0100 (2022-02-03) | 
| parents | 35e605322b41 | 
| children | 
 line source
     1 -- gets the corresponding ldap entry for a given member login
     2 -- --------------------------------------------------------------------------
     3 --
     4 -- arguments:
     5 --   filter: the LDAP filter for searching the member (required)
     6 --   use_ldap_conn: an already existing LDAP connection to be used (optional)
     7 --
     8 -- returns:
     9 --   ldap_entry: in case of success, the LDAP entry (object)
    10 --   err: in case of an error, an error message (string)
    11 --   err2: error dependent extra error information
    13 function ldap.get_member_entry(filter, use_ldap_conn)
    15   local ldap_conn, err, bind_err
    17   if use_ldap_conn then
    18     ldap_conn = use_ldap_conn
    19   else
    20     ldap_conn, bind_err = ldap.bind_as_app()
    21   end
    23   if not ldap_conn then
    24     return nil, "ldap_bind_error", bind_err
    25   end
    27   local entries, search_err = ldap_conn:search{
    28     base = config.ldap.base,
    29     scope = config.ldap.member.scope,
    30     filter = filter,
    31     attrs = config.ldap.member.fetch_attr,
    32   }
    34   if not use_ldap_conn then
    35     ldap_conn:unbind()
    36   end
    38   if not entries then
    39     return nil, "ldap_search_error", search_err
    40   end
    42   if #entries > 1 then
    43     return nil, "too_many_ldap_entries_found"
    44   end
    46   if #entries < 0 then
    47     return nil, "no_ldap_entry_found"
    48   end
    50   return entries[1]
    52 end
