109 lines
4.1 KiB
Elixir
109 lines
4.1 KiB
Elixir
defmodule MvWeb.SignInLive do
|
|
@moduledoc """
|
|
Custom sign-in page with public header and hero layout (same as Join/Join Confirm).
|
|
|
|
Uses Layouts.public_page (no sidebar, no app-layout hooks). Wraps the AshAuthentication
|
|
SignIn component in a hero section. Container has data-oidc-configured so CSS can hide
|
|
the SSO button when OIDC is not configured.
|
|
|
|
Keeps `use Phoenix.LiveView` (not MvWeb :live_view) so AshAuthentication's sign_in_route
|
|
live_session on_mount chain is not mixed with LiveHelpers hooks.
|
|
|
|
## Locale overrides
|
|
`MvWeb.AuthOverridesDE` is prepended to the overrides list when the locale is "de",
|
|
providing static German strings for components that do not use `_gettext` internally
|
|
(e.g. HorizontalRule renders its `:text` override directly).
|
|
"""
|
|
use Phoenix.LiveView
|
|
use Gettext, backend: MvWeb.Gettext
|
|
|
|
alias AshAuthentication.Phoenix.Components
|
|
alias Mv.Config
|
|
alias MvWeb.{AuthOverridesDE, Layouts}
|
|
|
|
@impl true
|
|
def mount(_params, session, socket) do
|
|
# Locale: same fallback as LiveUserAuth so config :default_locale (e.g. "en" in test) is respected
|
|
locale = session["locale"] || Application.get_env(:mv, :default_locale, "de")
|
|
|
|
# Set both backend-specific and global locale so Gettext.get_locale/0 and
|
|
# Gettext.get_locale/1 both return the correct value (important for the
|
|
# language-selector `selected` attribute in Layouts.public_page).
|
|
Gettext.put_locale(MvWeb.Gettext, locale)
|
|
Gettext.put_locale(locale)
|
|
|
|
# Prepend DE-specific overrides when locale is German so that components
|
|
# without _gettext support (e.g. HorizontalRule) still render in German.
|
|
base_overrides = Map.get(session, "overrides", [AshAuthentication.Phoenix.Overrides.Default])
|
|
locale_overrides = if locale == "de", do: [AuthOverridesDE], else: []
|
|
overrides = locale_overrides ++ base_overrides
|
|
|
|
socket =
|
|
socket
|
|
|> assign(overrides: overrides)
|
|
|> assign_new(:otp_app, fn -> nil end)
|
|
|> assign(:path, session["path"] || "/")
|
|
|> assign(:reset_path, session["reset_path"])
|
|
|> assign(:register_path, session["register_path"])
|
|
|> assign(:current_tenant, session["tenant"])
|
|
|> assign(:resources, session["resources"])
|
|
|> assign(:context, session["context"] || %{})
|
|
|> assign(:auth_routes_prefix, session["auth_routes_prefix"])
|
|
|> assign(:gettext_fn, session["gettext_fn"])
|
|
|> assign_new(:live_action, fn -> :sign_in end)
|
|
|> assign(:oidc_configured, Config.oidc_configured?())
|
|
|> assign(:oidc_only, Config.oidc_only?())
|
|
|> assign(:sign_in_id, "sign-in")
|
|
|> assign(:locale, locale)
|
|
|
|
{:ok, socket}
|
|
end
|
|
|
|
@impl true
|
|
def handle_params(_, _uri, socket) do
|
|
{:noreply, socket}
|
|
end
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.public_page flash={@flash}>
|
|
<div class="max-w-4xl mx-auto">
|
|
<div
|
|
class="hero min-h-[60vh] bg-base-200 rounded-lg"
|
|
id="sign-in-page"
|
|
role="main"
|
|
data-oidc-configured={to_string(@oidc_configured)}
|
|
data-oidc-only={to_string(@oidc_only)}
|
|
data-locale={@locale}
|
|
>
|
|
<div class="hero-content flex-col items-start text-left">
|
|
<div class="w-full max-w-md">
|
|
<h1 class="text-xl font-semibold leading-8">
|
|
{if @live_action == :register,
|
|
do: dgettext("auth", "Register"),
|
|
else: dgettext("auth", "Sign in")}
|
|
</h1>
|
|
<.live_component
|
|
module={Components.SignIn}
|
|
otp_app={@otp_app}
|
|
live_action={@live_action}
|
|
path={@path}
|
|
auth_routes_prefix={@auth_routes_prefix}
|
|
resources={@resources}
|
|
reset_path={@reset_path}
|
|
register_path={@register_path}
|
|
id={@sign_in_id}
|
|
overrides={@overrides}
|
|
current_tenant={@current_tenant}
|
|
context={@context}
|
|
gettext_fn={@gettext_fn}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Layouts.public_page>
|
|
"""
|
|
end
|
|
end
|