ash_authentication/dev/dev_server/test_page.ex
James Harton a939dde9b9
feat(PasswordAuthentication): Registration and authentication with local credentials (#4)
This is missing a bunch of features that you probably want to use (eg confirmation, password resets), but it's a pretty good place to put a stake in the sand and say it works.
2022-10-25 11:07:07 +13:00

37 lines
890 B
Elixir

defmodule DevServer.TestPage do
@moduledoc """
Displays a very basic login form according to the currently configured
Überauth providers.
"""
@behaviour Plug
alias Plug.Conn
require EEx
EEx.function_from_file(:defp, :render, String.replace(__ENV__.file, ".ex", ".html.eex"), [
:assigns
])
@doc false
@impl true
@spec init(keyword) :: keyword
def init(opts), do: opts
@doc false
@spec call(Conn.t(), any) :: Conn.t()
@impl true
def call(conn, _opts) do
resources = AshAuthentication.authenticated_resources(:ash_authentication)
current_actors =
conn.assigns
|> Stream.filter(fn {key, _value} ->
key
|> to_string()
|> String.starts_with?("current_")
end)
|> Map.new()
payload = render(resources: resources, current_actors: current_actors)
Conn.send_resp(conn, 200, payload)
end
end