From a46be28b53f2875b1a0902b0cfd33ce492e93ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Tue, 30 Jun 2015 21:02:58 +0200 Subject: [PATCH] [fix] Construct a proper emails array (fix #39) --- helpers.lua | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/helpers.lua b/helpers.lua index 06b1e95..9142628 100644 --- a/helpers.lua +++ b/helpers.lua @@ -613,14 +613,18 @@ function edit_user () filter = "(uid="..user..")", attrs = {"mail"} } do + -- Construct proper emails array + local mail_list = {} + local mail_attr = attribs["mail"] + if type(mail_attr) == "string" then + mail_list = { mail_attr } + elseif type(mail_attr) == "table" then + mail_list = mail_attr + end + -- Filter configuration's domain list to keep only -- "allowed" domains for _, domain in ipairs(conf["domains"]) do - if type(attribs["mail"] == "string") then - mail_list = { attribs["mail"] } - else - mail_list = attribs["mail"] - end for k, mail in ipairs(mail_list) do if string.ends(mail, "@"..domain) then if not is_in_table(domains, domain) then @@ -705,10 +709,16 @@ function edit_user () } do -- Another user with one of these emails has been found. if attribs[conf["ldap_identifier"]] and attribs[conf["ldap_identifier"]] ~= user then - if type(attribs["mail"]) == "string" then - attribs["mail"] = {attribs["mail"]} + -- Construct proper emails array + local mail_list = {} + local mail_attr = attribs["mail"] + if type(mail_attr) == "string" then + mail_list = { mail_attr } + elseif type(mail_attr) == "table" then + mail_list = mail_attr end - for _, mail in ipairs(attribs["mail"]) do + + for _, mail in ipairs(mail_list) do if is_in_table(mails, mail) then flash("fail", t("mail_already_used").." "..mail) end