All checks were successful
deploy / deploy (push) Successful in 1m31s
- add password field and required shop name to setup wizard - extract SetupHook for DRY redirect to /setup when no admin exists - add ?from=checklist param to checklist hrefs with contextual banner on email settings and theme pages for easy return to dashboard - remove email warning banner from admin layout (checklist covers it) - make email a required checklist item (no longer optional) - add DevReset module for wiping dev data without restart - rename "Theme Studio" to "Theme", drop subtitle - lower theme editor side-by-side breakpoint from 64em to 48em - clean up login/registration pages (remove dead registration_open code) - fix settings.put_secret to invalidate cache after write Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
91 lines
2.6 KiB
Elixir
91 lines
2.6 KiB
Elixir
defmodule BerrypodWeb.Auth.Registration do
|
|
use BerrypodWeb, :live_view
|
|
|
|
alias Berrypod.Accounts
|
|
alias Berrypod.Accounts.User
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
|
<div class="mx-auto max-w-sm">
|
|
<div class="text-center">
|
|
<.header>
|
|
Register for an account
|
|
<:subtitle>
|
|
Already registered?
|
|
<.link navigate={~p"/users/log-in"} class="font-semibold text-brand hover:underline">
|
|
Log in
|
|
</.link>
|
|
to your account now.
|
|
</:subtitle>
|
|
</.header>
|
|
</div>
|
|
|
|
<.form for={@form} id="registration_form" phx-submit="save" phx-change="validate">
|
|
<.input
|
|
field={@form[:email]}
|
|
type="email"
|
|
label="Email"
|
|
autocomplete="username"
|
|
required
|
|
phx-mounted={JS.focus()}
|
|
/>
|
|
|
|
<.button phx-disable-with="Creating account..." variant="primary" class="w-full">
|
|
Create an account
|
|
</.button>
|
|
</.form>
|
|
</div>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, %{assigns: %{current_scope: %{user: user}}} = socket)
|
|
when not is_nil(user) do
|
|
{:ok, redirect(socket, to: BerrypodWeb.UserAuth.signed_in_path(socket))}
|
|
end
|
|
|
|
def mount(_params, _session, socket) do
|
|
# Admin exists (hook handles no-admin), registration is single-user only
|
|
{:ok,
|
|
socket
|
|
|> put_flash(:error, "Registration is closed")
|
|
|> redirect(to: ~p"/users/log-in")}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("save", %{"user" => user_params}, socket) do
|
|
case Accounts.register_user(user_params) do
|
|
{:ok, user} ->
|
|
{:ok, _} =
|
|
Accounts.deliver_login_instructions(
|
|
user,
|
|
&url(~p"/users/log-in/#{&1}")
|
|
)
|
|
|
|
{:noreply,
|
|
socket
|
|
|> put_flash(
|
|
:info,
|
|
"An email was sent to #{user.email}, please access it to confirm your account."
|
|
)
|
|
|> push_navigate(to: ~p"/users/log-in")}
|
|
|
|
{:error, %Ecto.Changeset{} = changeset} ->
|
|
{:noreply, assign_form(socket, changeset)}
|
|
end
|
|
end
|
|
|
|
def handle_event("validate", %{"user" => user_params}, socket) do
|
|
changeset = Accounts.change_user_email(%User{}, user_params, validate_unique: false)
|
|
{:noreply, assign_form(socket, Map.put(changeset, :action, :validate))}
|
|
end
|
|
|
|
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
|
|
form = to_form(changeset, as: "user")
|
|
assign(socket, form: form)
|
|
end
|
|
end
|