Add possibility to create users with provider (such as LDAP)

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-07-22 15:09:12 +02:00
parent 395675ce6a
commit fa8cae681f
6 changed files with 133 additions and 25 deletions

View File

@@ -22,6 +22,7 @@ defmodule Mobilizon.Service.Auth.LDAPAuthenticator do
@connection_timeout 10_000
@search_timeout 10_000
@impl Authenticator
def login(email, password) do
with {:ldap, true} <- {:ldap, Mobilizon.Config.get([:ldap, :enabled])},
%User{} = user <- ldap_user(email, password) do
@@ -39,10 +40,15 @@ defmodule Mobilizon.Service.Auth.LDAPAuthenticator do
end
end
@impl Authenticator
def can_change_email?(%User{provider: provider}), do: provider != "ldap"
@impl Authenticator
def can_change_password?(%User{provider: provider}), do: provider != "ldap"
@impl Authenticator
def provider_name, do: "ldap"
defp ldap_user(email, password) do
ldap = Mobilizon.Config.get(:ldap, [])
host = Keyword.get(ldap, :host, "localhost")