api-v2/deps/phoenix/priv/templates/phx.gen.auth/confirmation_instructions_live.ex
2025-04-16 10:03:13 -03:00

52 lines
1.8 KiB
Elixir

defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>ConfirmationInstructionsLive do
use <%= inspect context.web_module %>, :live_view
alias <%= inspect context.module %>
def render(assigns) do
~H"""
<div class="mx-auto max-w-sm">
<.header class="text-center">
No confirmation instructions received?
<:subtitle>We'll send a new confirmation link to your inbox</:subtitle>
</.header>
<.simple_form for={@form} id="resend_confirmation_form" phx-submit="send_instructions">
<.input field={@form[:email]} type="email" placeholder="Email" required />
<:actions>
<.button phx-disable-with="Sending..." class="w-full">
Resend confirmation instructions
</.button>
</:actions>
</.simple_form>
<p class="text-center mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
</p>
</div>
"""
end
def mount(_params, _session, socket) do
{:ok, assign(socket, form: to_form(%{}, as: "<%= schema.singular %>"))}
end
def handle_event("send_instructions", %{"<%= schema.singular %>" => %{"email" => email}}, socket) do
if <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>_by_email(email) do
<%= inspect context.alias %>.deliver_<%= schema.singular %>_confirmation_instructions(
<%= schema.singular %>,
&url(~p"<%= schema.route_prefix %>/confirm/#{&1}")
)
end
info =
"If your email is in our system and it has not been confirmed yet, you will receive an email with instructions shortly."
{:noreply,
socket
|> put_flash(:info, info)
|> redirect(to: ~p"/")}
end
end