forked from AkkomaGang/akkoma
Remove LDAP mail attribute as a requirement for registering an account
This commit is contained in:
parent
b1b6a7dfa8
commit
f7146583e5
2 changed files with 12 additions and 22 deletions
|
@ -105,29 +105,21 @@ defp register_user(connection, base, uid, name, password) do
|
||||||
{:base, to_charlist(base)},
|
{:base, to_charlist(base)},
|
||||||
{:filter, :eldap.equalityMatch(to_charlist(uid), to_charlist(name))},
|
{:filter, :eldap.equalityMatch(to_charlist(uid), to_charlist(name))},
|
||||||
{:scope, :eldap.wholeSubtree()},
|
{:scope, :eldap.wholeSubtree()},
|
||||||
{:attributes, ['mail', 'email']},
|
|
||||||
{:timeout, @search_timeout}
|
{:timeout, @search_timeout}
|
||||||
]) do
|
]) do
|
||||||
{:ok, {:eldap_search_result, [{:eldap_entry, _, attributes}], _}} ->
|
{:ok, {:eldap_search_result, [{:eldap_entry, _, _}], _}} ->
|
||||||
with {_, [mail]} <- List.keyfind(attributes, 'mail', 0) do
|
params = %{
|
||||||
params = %{
|
name: name,
|
||||||
email: :erlang.list_to_binary(mail),
|
nickname: name,
|
||||||
name: name,
|
password: password,
|
||||||
nickname: name,
|
password_confirmation: password
|
||||||
password: password,
|
}
|
||||||
password_confirmation: password
|
|
||||||
}
|
|
||||||
|
|
||||||
changeset = User.register_changeset(%User{}, params)
|
changeset = User.register_changeset(%User{}, params)
|
||||||
|
|
||||||
case User.register(changeset) do
|
case User.register(changeset) do
|
||||||
{:ok, user} -> user
|
{:ok, user} -> user
|
||||||
error -> error
|
error -> error
|
||||||
end
|
|
||||||
else
|
|
||||||
_ ->
|
|
||||||
Logger.error("Could not find LDAP attribute mail: #{inspect(attributes)}")
|
|
||||||
{:error, :ldap_registration_missing_attributes}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
error ->
|
error ->
|
||||||
|
|
|
@ -72,9 +72,7 @@ test "creates a new user after successful LDAP authorization" do
|
||||||
equalityMatch: fn _type, _value -> :ok end,
|
equalityMatch: fn _type, _value -> :ok end,
|
||||||
wholeSubtree: fn -> :ok end,
|
wholeSubtree: fn -> :ok end,
|
||||||
search: fn _connection, _options ->
|
search: fn _connection, _options ->
|
||||||
{:ok,
|
{:ok, {:eldap_search_result, [{:eldap_entry, '', []}], []}}
|
||||||
{:eldap_search_result, [{:eldap_entry, '', [{'mail', [to_charlist(user.email)]}]}],
|
|
||||||
[]}}
|
|
||||||
end,
|
end,
|
||||||
close: fn _connection ->
|
close: fn _connection ->
|
||||||
send(self(), :close_connection)
|
send(self(), :close_connection)
|
||||||
|
|
Loading…
Reference in a new issue