2026-02-18 21:23:15 +00:00
|
|
|
defmodule BerrypodWeb.Auth.Login do
|
|
|
|
|
use BerrypodWeb, :live_view
|
2025-12-30 12:26:46 +00:00
|
|
|
|
2026-02-21 21:40:53 +00:00
|
|
|
alias Berrypod.{Accounts, Mailer}
|
2025-12-30 12:26:46 +00:00
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def render(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
2026-03-04 17:12:21 +00:00
|
|
|
<div class="setup-page">
|
|
|
|
|
<div class="setup-header">
|
2025-12-30 12:26:46 +00:00
|
|
|
<.header>
|
2026-03-04 17:12:21 +00:00
|
|
|
Log in
|
2025-12-30 12:26:46 +00:00
|
|
|
<:subtitle>
|
2026-03-03 17:41:08 +00:00
|
|
|
<%= if @current_scope do %>
|
|
|
|
|
You need to reauthenticate to perform sensitive actions on your account.
|
|
|
|
|
<% else %>
|
|
|
|
|
Log in with your admin credentials.
|
2025-12-30 12:26:46 +00:00
|
|
|
<% end %>
|
|
|
|
|
</:subtitle>
|
|
|
|
|
</.header>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-17 23:05:01 +00:00
|
|
|
<div :if={local_mail_adapter?()} class="admin-alert admin-alert-info">
|
2025-12-30 12:26:46 +00:00
|
|
|
<.icon name="hero-information-circle" class="size-6 shrink-0" />
|
|
|
|
|
<div>
|
|
|
|
|
<p>You are running the local mail adapter.</p>
|
|
|
|
|
<p>
|
2026-03-04 17:12:21 +00:00
|
|
|
To see sent emails, visit <.link href="/dev/mailbox" class="admin-link">the mailbox page</.link>.
|
2025-12-30 12:26:46 +00:00
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-02-21 21:40:53 +00:00
|
|
|
<%= if @email_configured do %>
|
|
|
|
|
<.form
|
|
|
|
|
:let={f}
|
|
|
|
|
for={@form}
|
|
|
|
|
id="login_form_magic"
|
|
|
|
|
action={~p"/users/log-in"}
|
|
|
|
|
phx-submit="submit_magic"
|
|
|
|
|
>
|
2026-03-08 18:42:29 +00:00
|
|
|
<input :if={@return_to} type="hidden" name="return_to" value={@return_to} />
|
2026-02-21 21:40:53 +00:00
|
|
|
<.input
|
|
|
|
|
readonly={!!@current_scope}
|
|
|
|
|
field={f[:email]}
|
|
|
|
|
type="email"
|
|
|
|
|
label="Email"
|
|
|
|
|
autocomplete="email"
|
|
|
|
|
required
|
|
|
|
|
phx-mounted={JS.focus()}
|
|
|
|
|
/>
|
2026-03-04 17:12:21 +00:00
|
|
|
<.button variant="primary" class="admin-btn-block">
|
|
|
|
|
Log in with email <span aria-hidden="true">→</span>
|
2026-02-21 21:40:53 +00:00
|
|
|
</.button>
|
|
|
|
|
</.form>
|
2025-12-30 12:26:46 +00:00
|
|
|
|
2026-02-21 21:40:53 +00:00
|
|
|
<div class="admin-divider">or</div>
|
|
|
|
|
<% end %>
|
2025-12-30 12:26:46 +00:00
|
|
|
|
|
|
|
|
<.form
|
|
|
|
|
:let={f}
|
|
|
|
|
for={@form}
|
|
|
|
|
id="login_form_password"
|
|
|
|
|
action={~p"/users/log-in"}
|
|
|
|
|
phx-submit="submit_password"
|
|
|
|
|
phx-trigger-action={@trigger_submit}
|
|
|
|
|
>
|
2026-03-08 18:42:29 +00:00
|
|
|
<input :if={@return_to} type="hidden" name="return_to" value={@return_to} />
|
2025-12-30 12:26:46 +00:00
|
|
|
<.input
|
|
|
|
|
readonly={!!@current_scope}
|
|
|
|
|
field={f[:email]}
|
|
|
|
|
type="email"
|
|
|
|
|
label="Email"
|
|
|
|
|
autocomplete="email"
|
|
|
|
|
required
|
|
|
|
|
/>
|
|
|
|
|
<.input
|
|
|
|
|
field={@form[:password]}
|
|
|
|
|
type="password"
|
|
|
|
|
label="Password"
|
|
|
|
|
autocomplete="current-password"
|
|
|
|
|
/>
|
2026-03-04 17:12:21 +00:00
|
|
|
<.button
|
|
|
|
|
variant="primary"
|
|
|
|
|
class="admin-btn-block"
|
|
|
|
|
name={@form[:remember_me].name}
|
|
|
|
|
value="true"
|
|
|
|
|
>
|
|
|
|
|
Log in and stay logged in <span aria-hidden="true">→</span>
|
2025-12-30 12:26:46 +00:00
|
|
|
</.button>
|
2026-03-04 17:12:21 +00:00
|
|
|
<.button class="admin-btn-block">
|
2025-12-30 12:26:46 +00:00
|
|
|
Log in only this time
|
|
|
|
|
</.button>
|
|
|
|
|
</.form>
|
2026-02-21 21:40:53 +00:00
|
|
|
|
2026-03-04 17:12:21 +00:00
|
|
|
<p :if={!@email_configured} class="setup-footer">
|
2026-02-21 21:40:53 +00:00
|
|
|
Locked out?
|
2026-03-04 17:12:21 +00:00
|
|
|
<.link navigate={~p"/recover"} class="admin-link">
|
2026-02-21 21:40:53 +00:00
|
|
|
Recover with setup secret
|
|
|
|
|
</.link>
|
|
|
|
|
</p>
|
2025-12-30 12:26:46 +00:00
|
|
|
</div>
|
|
|
|
|
</Layouts.app>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@impl true
|
2026-03-08 18:42:29 +00:00
|
|
|
def mount(params, _session, socket) do
|
2025-12-30 12:26:46 +00:00
|
|
|
email =
|
|
|
|
|
Phoenix.Flash.get(socket.assigns.flash, :email) ||
|
|
|
|
|
get_in(socket.assigns, [:current_scope, Access.key(:user), Access.key(:email)])
|
|
|
|
|
|
|
|
|
|
form = to_form(%{"email" => email}, as: "user")
|
2026-03-08 18:42:29 +00:00
|
|
|
return_to = params["return_to"]
|
2025-12-30 12:26:46 +00:00
|
|
|
|
add setup onboarding page, dashboard launch checklist, provider registry
- new /setup page with three-section onboarding (account, provider, payments)
- dashboard launch checklist with progress bar, go-live, dismiss
- provider registry on Provider module (single source of truth for metadata)
- payments registry for Stripe
- setup context made provider-agnostic (provider_connected, theme_customised, etc.)
- admin provider pages now fully registry-driven (no hardcoded provider names)
- auth flow: fresh installs redirect to /setup, signed_in_path respects setup state
- removed old /admin/setup wizard
- 840 tests, 0 failures
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 00:34:06 +00:00
|
|
|
{:ok,
|
2026-02-21 21:40:53 +00:00
|
|
|
assign(socket,
|
|
|
|
|
form: form,
|
|
|
|
|
trigger_submit: false,
|
2026-03-08 18:42:29 +00:00
|
|
|
email_configured: Mailer.email_verified?(),
|
|
|
|
|
return_to: return_to
|
2026-02-21 21:40:53 +00:00
|
|
|
)}
|
2025-12-30 12:26:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
|
def handle_event("submit_password", _params, socket) do
|
|
|
|
|
{:noreply, assign(socket, :trigger_submit, true)}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def handle_event("submit_magic", %{"user" => %{"email" => email}}, socket) do
|
|
|
|
|
if user = Accounts.get_user_by_email(email) do
|
|
|
|
|
Accounts.deliver_login_instructions(
|
|
|
|
|
user,
|
|
|
|
|
&url(~p"/users/log-in/#{&1}")
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
info =
|
|
|
|
|
"If your email is in our system, you will receive instructions for logging in shortly."
|
|
|
|
|
|
|
|
|
|
{:noreply,
|
|
|
|
|
socket
|
|
|
|
|
|> put_flash(:info, info)
|
|
|
|
|
|> push_navigate(to: ~p"/users/log-in")}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
defp local_mail_adapter? do
|
2026-02-18 21:23:15 +00:00
|
|
|
Application.get_env(:berrypod, Berrypod.Mailer)[:adapter] ==
|
2026-01-31 14:24:58 +00:00
|
|
|
Swoosh.Adapters.Local
|
2025-12-30 12:26:46 +00:00
|
|
|
end
|
|
|
|
|
end
|