62 lines
1.6 KiB
Elixir
62 lines
1.6 KiB
Elixir
defmodule BeetRoundServerWeb.UserLive.Login do
|
|
use BeetRoundServerWeb, :live_view
|
|
|
|
alias BeetRoundServer.Accounts
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
|
<div class="mx-auto max-w-sm space-y-4">
|
|
<div class="text-center">
|
|
<.header>
|
|
<p>Log in</p>
|
|
<:subtitle>
|
|
Bitte nutze deinen persönlichen Link der dir per Mail zugesendet wurde um dich anzumelden.
|
|
</:subtitle>
|
|
</.header>
|
|
</div>
|
|
</div>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
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")
|
|
|
|
{:ok, assign(socket, form: form, trigger_submit: false)}
|
|
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
|
|
Application.get_env(:beet_round_server, BeetRoundServer.Mailer)[:adapter] ==
|
|
Swoosh.Adapters.Local
|
|
end
|
|
end
|