Add email to user account only if it exists in LDAP
[akkoma] / lib / pleroma / web / auth / ldap_authenticator.ex
index f667da68b90fa726a04c84c8e0ec41cdcf878455..b1645a3591d9aa58a78872608bde203a888a6828 100644 (file)
@@ -103,13 +103,19 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
            {:scope, :eldap.wholeSubtree()},
            {:timeout, @search_timeout}
          ]) do
-      {:ok, {:eldap_search_result, [{:eldap_entry, _, _}], _}} ->
+      {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
         params = %{
           name: name,
           nickname: name,
           password: nil
         }
 
+        params =
+          case List.keyfind(attributes, 'mail', 0) do
+            {_, [mail]} -> Map.put_new(params, :email, :erlang.list_to_binary(mail))
+            _ -> params
+          end
+
         changeset = User.register_changeset(%User{}, params)
 
         case User.register(changeset) do