Files
chess-endgame-trainer/lib/chesstrainer_web/live/user_live/login.ex
T
owenrees fa1fef7b62 Launch amendments: one login, crawler policy, and asset caching (#180)
* lesson library shown as com,ing soon. re-enable learngin strip

* replace learning strip text with a lasker quote

* remove admin login endpoint

* fix crawler directives and prelaunch login

- noindex the authenticated scope and the 404 catch-all, and cover the
  mailing-list confirmation redirect
- emit noindex, nofollow from the robots meta and /health, and assert
  public pages stay indexable and followable
- stop inventing lastmod values in the sitemap
- log in through /users/log-in during prelaunch now that the admin login
  endpoint is gone; drop create_admin/2 and its orphaned tests

* update caching length to 1 year - name change will invalidate cache

* remove logger

* fix tablebase path breaking tests

* test: check cache headers without requiring built assets

CI's test job does not run mix assets.build, so /assets/css/app.css is a
404 there. Committed piece art is already content-hashed and takes the same
Plug.Static cache option, so the test no longer needs a build step and
passes on a fresh checkout.
2026-11-17 12:55:47 +01:00

92 lines
2.6 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={~p"/users/log-in"}
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")
{:ok,
assign(socket,
form: form,
trigger_submit: false,
prelaunch: ChesstrainerWeb.prelaunch?()
)}
end
@impl true
def handle_event("submit_password", _params, socket) do
{:noreply, assign(socket, :trigger_submit, true)}
end
end