Add email to user account only if it exists in LDAP

This commit is contained in:
Mark Felder 2020-08-05 11:36:12 -05:00
parent 2192d1e492
commit 81126b0142
2 changed files with 16 additions and 1 deletions

View File

@ -643,12 +643,21 @@ defmodule Pleroma.User do
when is_nil(password) do when is_nil(password) do
params = Map.put_new(params, :accepts_chat_messages, true) params = Map.put_new(params, :accepts_chat_messages, true)
params =
if Map.has_key?(params, :email) do
Map.put_new(params, :email, params[:email])
else
params
end
struct struct
|> cast(params, [ |> cast(params, [
:name, :name,
:nickname, :nickname,
:email,
:accepts_chat_messages :accepts_chat_messages
]) ])
|> validate_required([:name, :nickname])
|> unique_constraint(:nickname) |> unique_constraint(:nickname)
|> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames])) |> validate_exclusion(:nickname, Config.get([User, :restricted_nicknames]))
|> validate_format(:nickname, local_nickname_regex()) |> validate_format(:nickname, local_nickname_regex())

View File

@ -103,13 +103,19 @@ defmodule Pleroma.Web.Auth.LDAPAuthenticator do
{:scope, :eldap.wholeSubtree()}, {:scope, :eldap.wholeSubtree()},
{:timeout, @search_timeout} {:timeout, @search_timeout}
]) do ]) do
{:ok, {:eldap_search_result, [{:eldap_entry, _, _}], _}} -> {:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
params = %{ params = %{
name: name, name: name,
nickname: name, nickname: name,
password: nil 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) changeset = User.register_changeset(%User{}, params)
case User.register(changeset) do case User.register(changeset) do