2023-07-28 20:44:00 +00:00
|
|
|
defmodule PrymnWeb.UserLoginLive do
|
|
|
|
use PrymnWeb, :live_view
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def render(assigns) do
|
|
|
|
~H"""
|
|
|
|
<div class="mx-auto max-w-sm">
|
2023-12-13 15:41:46 +00:00
|
|
|
<.header class="mb-10 text-center">
|
2023-07-28 20:44:00 +00:00
|
|
|
Sign in to account
|
|
|
|
<:subtitle>
|
|
|
|
Don't have an account?
|
|
|
|
<.link navigate={~p"/auth/register"} class="text-brand font-semibold hover:underline">
|
|
|
|
Sign up
|
|
|
|
</.link>
|
|
|
|
for an account now.
|
|
|
|
</:subtitle>
|
|
|
|
</.header>
|
|
|
|
|
|
|
|
<.simple_form for={@form} id="login_form" action={~p"/auth/log_in"} phx-update="ignore">
|
|
|
|
<.error :if={@error}>
|
|
|
|
Could not sign in: <%= @error %>
|
|
|
|
</.error>
|
|
|
|
|
|
|
|
<.input
|
|
|
|
field={@form[:email]}
|
|
|
|
type="email"
|
|
|
|
label="Email"
|
|
|
|
placeholder="hello@example.com"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<.input field={@form[:password]} type="password" label="Password" required />
|
|
|
|
|
|
|
|
<:actions>
|
|
|
|
<.input field={@form[:remember_me]} type="checkbox" label="Keep me logged in" />
|
|
|
|
<.link href={~p"/auth/reset_password"} class="text-sm font-semibold">
|
|
|
|
Forgot your password?
|
|
|
|
</.link>
|
|
|
|
</:actions>
|
|
|
|
<:actions>
|
2023-11-23 13:45:33 +00:00
|
|
|
<Button.primary phx-disable-with="Signing in..." class="w-full">Sign in</Button.primary>
|
2023-07-28 20:44:00 +00:00
|
|
|
</:actions>
|
|
|
|
</.simple_form>
|
|
|
|
</div>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def mount(params, _session, socket) do
|
|
|
|
form = to_form(%{"email" => params["email"] || nil}, as: "user")
|
|
|
|
error = Phoenix.Flash.get(socket.assigns.flash, "login_error")
|
|
|
|
|
|
|
|
{:ok, assign(socket, form: form, error: error), temporary_assigns: [form: form]}
|
|
|
|
end
|
|
|
|
end
|