This commit is contained in:
parent
f12da8a359
commit
349cee0ce6
19 changed files with 300 additions and 100 deletions
|
|
@ -12,12 +12,22 @@ defmodule MvWeb.JoinLive do
|
|||
# Honeypot field name (legitimate-sounding to avoid bot detection)
|
||||
@honeypot_field "website"
|
||||
|
||||
# Anti-enumeration: delay before showing success (ms). Applied in LiveView so the process is not blocked.
|
||||
@anti_enumeration_delay_ms_min 100
|
||||
@anti_enumeration_delay_ms_rand 200
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
allowlist = Membership.get_join_form_allowlist()
|
||||
join_fields = build_join_fields_with_labels(allowlist)
|
||||
client_ip = client_ip_from_socket(socket)
|
||||
|
||||
club_name =
|
||||
case Membership.get_settings() do
|
||||
{:ok, s} -> s.club_name || "Mitgliederverwaltung"
|
||||
_ -> "Mitgliederverwaltung"
|
||||
end
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:join_fields, join_fields)
|
||||
|
|
@ -25,6 +35,7 @@ defmodule MvWeb.JoinLive do
|
|||
|> assign(:rate_limit_error, nil)
|
||||
|> assign(:client_ip, client_ip)
|
||||
|> assign(:honeypot_field, @honeypot_field)
|
||||
|> assign(:club_name, club_name)
|
||||
|> assign(:form, to_form(initial_form_params(join_fields)))
|
||||
|
||||
{:ok, socket}
|
||||
|
|
@ -33,7 +44,7 @@ defmodule MvWeb.JoinLive do
|
|||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<Layouts.public_page flash={@flash}>
|
||||
<Layouts.public_page flash={@flash} club_name={@club_name}>
|
||||
<div class="max-w-4xl mx-auto">
|
||||
<div class="hero min-h-[60vh] bg-base-200 rounded-lg">
|
||||
<div class="hero-content flex-col items-start text-left">
|
||||
|
|
@ -149,7 +160,11 @@ defmodule MvWeb.JoinLive do
|
|||
{:ok, attrs} ->
|
||||
case Membership.submit_join_request(attrs, actor: nil) do
|
||||
{:ok, _} ->
|
||||
{:noreply, assign(socket, :submitted, true)}
|
||||
delay_ms =
|
||||
@anti_enumeration_delay_ms_min + :rand.uniform(@anti_enumeration_delay_ms_rand)
|
||||
|
||||
Process.send_after(self(), :show_join_success, delay_ms)
|
||||
{:noreply, socket}
|
||||
|
||||
{:error, :email_delivery_failed} ->
|
||||
{:noreply,
|
||||
|
|
@ -181,6 +196,16 @@ defmodule MvWeb.JoinLive do
|
|||
|> assign(:form, to_form(params, as: "join"))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_info(:show_join_success, socket) do
|
||||
{:noreply, assign(socket, :submitted, true)}
|
||||
end
|
||||
|
||||
# Swoosh (e.g. in test) may send {:email, email} to the LiveView process; ignore.
|
||||
def handle_info(_msg, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp rate_limited_reply(socket, params) do
|
||||
{:noreply,
|
||||
socket
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue