logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

legacy_authentication_plug.ex (1016B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Plugs.LegacyAuthenticationPlug do
  5. import Plug.Conn
  6. alias Pleroma.Plugs.OAuthScopesPlug
  7. alias Pleroma.User
  8. def init(options) do
  9. options
  10. end
  11. def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
  12. def call(
  13. %{
  14. assigns: %{
  15. auth_user: %{password_hash: "$6$" <> _ = password_hash} = auth_user,
  16. auth_credentials: %{password: password}
  17. }
  18. } = conn,
  19. _
  20. ) do
  21. with ^password_hash <- :crypt.crypt(password, password_hash),
  22. {:ok, user} <-
  23. User.reset_password(auth_user, %{password: password, password_confirmation: password}) do
  24. conn
  25. |> assign(:auth_user, user)
  26. |> assign(:user, user)
  27. |> OAuthScopesPlug.skip_plug()
  28. else
  29. _ ->
  30. conn
  31. end
  32. end
  33. def call(conn, _) do
  34. conn
  35. end
  36. end