logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://anongit.hacktivis.me/git/pleroma.git/

ldap_authenticator.ex (1290B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Auth.LDAPAuthenticator do
  5. alias Pleroma.LDAP
  6. alias Pleroma.User
  7. import Pleroma.Web.Auth.Helpers, only: [fetch_credentials: 1]
  8. @behaviour Pleroma.Web.Auth.Authenticator
  9. @base Pleroma.Web.Auth.PleromaAuthenticator
  10. defdelegate get_registration(conn), to: @base
  11. defdelegate create_from_registration(conn, registration), to: @base
  12. defdelegate handle_error(conn, error), to: @base
  13. defdelegate auth_template, to: @base
  14. defdelegate oauth_consumer_template, to: @base
  15. def get_user(%Plug.Conn{} = conn) do
  16. with {:ldap, true} <- {:ldap, Pleroma.Config.get([:ldap, :enabled])},
  17. {:ok, {name, password}} <- fetch_credentials(conn),
  18. %User{} = user <- LDAP.bind_user(name, password) do
  19. {:ok, user}
  20. else
  21. {:ldap, _} ->
  22. @base.get_user(conn)
  23. error ->
  24. error
  25. end
  26. end
  27. def change_password(user, password, new_password, new_password) do
  28. case LDAP.change_password(user.nickname, password, new_password) do
  29. :ok -> {:ok, user}
  30. e -> e
  31. end
  32. end
  33. def change_password(_, _, _, _), do: {:error, :password_confirmation}
  34. end