mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
* Show rating changes in flashes and session UI (#146) - Flash the new rating and delta on every rated completion, with a dedicated success flash kind for solved puzzles - Move flash notifications to the top-left - Add a colour-coded rating-change pill and show the current rating with the session's net change in the train session bar - Show the user's rating and change beside the puzzle rating after an attempt, and show the finishing rating in the last-session summary * fix header component and start reusing it * Hide the sign-up link on the prelaunch admin login The header refactor dropped the @prelaunch guard, so the gated admin login linked to the public registration page again.
97 lines
2.8 KiB
Elixir
97 lines
2.8 KiB
Elixir
defmodule ChesstrainerWeb.UserLive.Login do
|
|
use ChesstrainerWeb, :live_view
|
|
|
|
@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>
|
|
Log in
|
|
<:subtitle :if={@current_scope || !@prelaunch}>
|
|
<%= if @current_scope do %>
|
|
You need to reauthenticate to perform sensitive actions on your account.
|
|
<% else %>
|
|
Don't have an account? <.link
|
|
navigate={~p"/users/register"}
|
|
class="font-semibold text-primary-text hover:underline"
|
|
phx-no-format
|
|
>Sign up</.link> for an account now.
|
|
<% end %>
|
|
</:subtitle>
|
|
</.header>
|
|
</div>
|
|
|
|
<.form
|
|
:let={f}
|
|
for={@form}
|
|
id="login_form_password"
|
|
action={@login_action}
|
|
phx-submit="submit_password"
|
|
phx-trigger-action={@trigger_submit}
|
|
>
|
|
<.input
|
|
readonly={!!@current_scope}
|
|
field={f[:email]}
|
|
type="text"
|
|
label="Email or username"
|
|
autocomplete="username"
|
|
spellcheck="false"
|
|
required
|
|
/>
|
|
<.input
|
|
field={@form[:password]}
|
|
type="password"
|
|
label="Password"
|
|
autocomplete="current-password"
|
|
spellcheck="false"
|
|
/>
|
|
<.button variant="primary" class="w-full" name={@form[:remember_me].name} value="true">
|
|
Log in and stay logged in <span aria-hidden="true">→</span>
|
|
</.button>
|
|
<.button class="w-full mt-2">
|
|
Log in only this time
|
|
</.button>
|
|
</.form>
|
|
|
|
<p class="text-center text-sm">
|
|
<.link
|
|
navigate={~p"/users/reset-password"}
|
|
class="font-semibold text-primary-text hover:underline"
|
|
>
|
|
Forgot your password?
|
|
</.link>
|
|
</p>
|
|
</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")
|
|
prelaunch = ChesstrainerWeb.prelaunch?()
|
|
|
|
login_action =
|
|
if prelaunch, do: ~p"/admin/log-in", else: ~p"/users/log-in"
|
|
|
|
{:ok,
|
|
assign(socket,
|
|
form: form,
|
|
trigger_submit: false,
|
|
prelaunch: prelaunch,
|
|
login_action: login_action
|
|
)}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("submit_password", _params, socket) do
|
|
{:noreply, assign(socket, :trigger_submit, true)}
|
|
end
|
|
end
|