mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
* Document the remote shell for production user management * add sitemap to footer links * remove border under theme selection * Add admin theme and user management (#144) Add /admin/themes CRUD and /admin/users list/detail with role and plan editing, guarded by a shared Policy module. Include last-super-admin and self-role protections plus structured id-only admin logs. Also add admin invitations, confirmation resends and password-reset emails, which work in development through the Swoosh mailbox before SES is configured. * Rate-limit password logins and emit auth events (#142) Add a two-bucket login throttle (5 failures per login, 10 per IP in a 15-minute window) and a shared client-address helper for controllers and LiveViews. Blocked attempts skip the database and bcrypt. Log auth.login.failed and auth.login.throttled warnings with boot-scoped HMAC addresses only, and stop repeated confirmation emails on unconfirmed login attempts. * Harden the production login edge for Cloudflare Document the layered login defence: the app throttle is primary, Caddy must pass Cloudflare's CF-Connecting-IP to the app, and Cloudflare edge rate limiting covers request floods. Update the reference Caddyfile to accept only Cloudflare ranges and reject direct-to-origin traffic, and document the exact Cloudflare dashboard rules. * Document 10-second Cloudflare rate-limit window Cloudflare may only offer a 10-second period. Keep the edge rule at 10 login POSTs per 10 seconds per IP and rely on the app's 15-minute login/address throttle for credential guessing. * Document Cloudflare limits for LiveView registration Registration submits over the shared LiveView socket, so a Cloudflare rule on POST /users/register will not count account creations. Note the app-level throttle/Turnstile options instead. * Document current Cloudflare free-plan edge controls Record the production setup: Cloudflare-only Caddy origins, Bot Fight Mode, and the 10-second login flood rule (10 POSTs per 10 seconds, 10-second block). Clarify that the application's 15-minute throttle remains the real credential lockout. * Auto-refresh Cloudflare CIDRs for Caddy Move the origin allowlist into a generated cloudflare-ranges.caddy imported by Caddy. Add an hourly systemd timer and script that fetch Cloudflare's v4/v6 lists, reject malformed responses, validate the candidate Caddyfile, and reload Caddy only when the ranges change. Restore the previous file on validation or reload failure. * Document Cloudflare CIDR refresher setup and operations Record the installed paths, permissions, timer checks, manual run, update procedure, and the direct-on-VPS setup fallback when the deploy directory is absent.
97 lines
3.1 KiB
Elixir
97 lines
3.1 KiB
Elixir
defmodule ChesstrainerWeb.EndgameLive.Show do
|
|
use ChesstrainerWeb, :live_view
|
|
|
|
alias Chesstrainer.Endgames
|
|
alias Chesstrainer.Game
|
|
alias Chesstrainer.Repo
|
|
alias Chesstrainer.Themes
|
|
|
|
import ChesstrainerWeb.Board.BoardComponent
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
game =
|
|
case Game.game_from_fen(assigns.endgame.fen, :endgame) do
|
|
{:ok, g} -> g
|
|
{:error, :invalid_fen, g} -> g
|
|
end
|
|
|
|
# TODO once we return {:error, :invalid_fen, game}, then put flash to show it is invalid
|
|
# write tests for this
|
|
|
|
assigns =
|
|
assigns
|
|
|> assign(:game, game)
|
|
|> assign(:game_type, :endgame)
|
|
|
|
~H"""
|
|
<Layouts.app flash={@flash} wide>
|
|
<Layouts.admin_nav current_scope={@current_scope} />
|
|
|
|
<.header>
|
|
Endgame {@endgame.id}
|
|
<:subtitle>This is a endgame record from your database.</:subtitle>
|
|
<:actions>
|
|
<.button navigate={~p"/admin/endgames"}>
|
|
<.icon name="hero-arrow-left" />
|
|
</.button>
|
|
<.button navigate={~p"/endgames/#{@endgame.public_code}/play"}>
|
|
<.icon name="hero-play" /> Play (opens trainer)
|
|
</.button>
|
|
<.button variant="primary" navigate={~p"/admin/endgames/#{@endgame.id}/edit?return_to=show"}>
|
|
<.icon name="hero-pencil-square" /> Edit endgame
|
|
</.button>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<.board game={@game} myself="board" interactive={false} />
|
|
|
|
<.list>
|
|
<:item title="Fen">{@endgame.fen}</:item>
|
|
<:item title="Key">{@endgame.key}</:item>
|
|
<:item title="Public code">
|
|
<span id="public-code" class="select-all">{@endgame.public_code}</span>
|
|
<button
|
|
id="copy-public-code"
|
|
type="button"
|
|
phx-hook=".CopyPublicCode"
|
|
data-code={@endgame.public_code}
|
|
class="ml-2 inline-flex cursor-pointer items-center justify-center rounded p-1.5"
|
|
title="Copy public code"
|
|
aria-label="Copy public code to clipboard"
|
|
>
|
|
<.icon name="hero-document-duplicate" class="w-3.5 h-3.5" />
|
|
</button>
|
|
</:item>
|
|
<:item title="Color">{@endgame.color}</:item>
|
|
<:item title="Rating">{round(@endgame.rating)}</:item>
|
|
<:item title="Message">{@endgame.message}</:item>
|
|
<:item title="Notes">{@endgame.notes}</:item>
|
|
<:item title="Result">{@endgame.result}</:item>
|
|
<:item title="Themes">{Enum.join(Themes.names(@endgame.themes), ", ")}</:item>
|
|
<:item title="Attempted">{@endgame.times_attempted}</:item>
|
|
<:item title="Solved">{@endgame.times_solved}</:item>
|
|
</.list>
|
|
|
|
<script :type={Phoenix.LiveView.ColocatedHook} name=".CopyPublicCode">
|
|
export default {
|
|
mounted() {
|
|
this.el.addEventListener("click", () => {
|
|
navigator.clipboard.writeText(this.el.dataset.code)
|
|
})
|
|
}
|
|
}
|
|
</script>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(%{"id" => id}, _session, socket) do
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Show Endgame")
|
|
|> assign(:endgame, Endgames.get_endgame!(id) |> Repo.preload(:themes))}
|
|
end
|
|
end
|