logo

pleroma

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

helpers.ex (1001B)


  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.Helpers do
  5. alias Pleroma.User
  6. @doc "Gets user by nickname or email for auth."
  7. @spec fetch_user(String.t()) :: User.t() | nil
  8. def fetch_user(name) do
  9. User.get_by_nickname_or_email(name)
  10. end
  11. # Gets name and password from conn
  12. #
  13. @spec fetch_credentials(Plug.Conn.t() | map()) ::
  14. {:ok, {name :: any, password :: any}} | {:error, :invalid_credentials}
  15. def fetch_credentials(%Plug.Conn{params: params} = _),
  16. do: fetch_credentials(params)
  17. def fetch_credentials(params) do
  18. case params do
  19. %{"authorization" => %{"name" => name, "password" => password}} ->
  20. {:ok, {name, password}}
  21. %{"grant_type" => "password", "username" => name, "password" => password} ->
  22. {:ok, {name, password}}
  23. _ ->
  24. {:error, :invalid_credentials}
  25. end
  26. end
  27. end