chiya/lib/chiya_web/live/user_forgot_password_live.ex

51 lines
1.4 KiB
Elixir
Raw Permalink Normal View History

2023-03-05 16:13:00 +01:00
defmodule ChiyaWeb.UserForgotPasswordLive do
use ChiyaWeb, :live_view
alias Chiya.Accounts
def render(assigns) do
~H"""
<div class="mx-auto max-w-sm">
<.header class="text-center">
Forgot your password?
<:subtitle>We'll send a password reset link to your inbox</:subtitle>
</.header>
<.simple_form for={@form} id="reset_password_form" phx-submit="send_email">
<.input field={@form[:email]} type="email" placeholder="Email" required />
<:actions>
<.button phx-disable-with="Sending..." class="w-full">
Send password reset instructions
</.button>
</:actions>
</.simple_form>
<p class="text-center mt-4">
2023-03-07 21:15:26 +01:00
<.link href={~p"/user/register"}>Register</.link>
2023-05-31 21:32:34 +02:00
| <.link href={~p"/user/log_in"}>Log in</.link>
2023-03-05 16:13:00 +01:00
</p>
</div>
"""
end
def mount(_params, _session, socket) do
{:ok, assign(socket, form: to_form(%{}, as: "user"))}
end
def handle_event("send_email", %{"user" => %{"email" => email}}, socket) do
if user = Accounts.get_user_by_email(email) do
Accounts.deliver_user_reset_password_instructions(
user,
2023-03-07 21:15:26 +01:00
&url(~p"/user/reset_password/#{&1}")
2023-03-05 16:13:00 +01:00
)
end
info =
"If your email is in our system, you will receive instructions to reset your password shortly."
{:noreply,
socket
|> put_flash(:info, info)
|> redirect(to: ~p"/")}
end
end