logo

pleroma

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

legacy_authentication_plug.ex (1000B)


  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.Web.Plugs.LegacyAuthenticationPlug do
  5. import Plug.Conn
  6. alias Pleroma.User
  7. def init(options) do
  8. options
  9. end
  10. def call(%{assigns: %{user: %User{}}} = conn, _), do: conn
  11. def call(
  12. %{
  13. assigns: %{
  14. auth_user: %{password_hash: "$6$" <> _ = password_hash} = auth_user,
  15. auth_credentials: %{password: password}
  16. }
  17. } = conn,
  18. _
  19. ) do
  20. with ^password_hash <- :crypt.crypt(password, password_hash),
  21. {:ok, user} <-
  22. User.reset_password(auth_user, %{password: password, password_confirmation: password}) do
  23. conn
  24. |> assign(:auth_user, user)
  25. |> assign(:user, user)
  26. |> Pleroma.Web.Plugs.OAuthScopesPlug.skip_plug()
  27. else
  28. _ ->
  29. conn
  30. end
  31. end
  32. def call(conn, _) do
  33. conn
  34. end
  35. end