Add email to user account only if it exists in LDAP
This commit is contained in:
parent
2192d1e492
commit
81126b0142
|
@ -643,12 +643,21 @@ def register_changeset(struct, params = %{password: password})
|
||||||
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())
|
||||||
|
|
|
@ -103,13 +103,19 @@ defp register_user(connection, base, uid, name) 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
|
||||||
|
|
Loading…
Reference in New Issue