This commit is contained in:
parent
104d945dd1
commit
cc1df449c6
9 changed files with 253 additions and 161 deletions
|
|
@ -6,6 +6,7 @@ defmodule MvWeb.JoinLive do
|
|||
use MvWeb, :live_view
|
||||
|
||||
alias Ash.Resource.Info
|
||||
alias Mv.Membership.CustomFieldLookup
|
||||
alias Mv.Membership
|
||||
alias MvWeb.JoinRateLimit
|
||||
alias MvWeb.Translations.MemberFields
|
||||
|
|
@ -87,6 +88,7 @@ defmodule MvWeb.JoinLive do
|
|||
<span class="label-text">{field.label}{if field.required, do: " *"}</span>
|
||||
</label>
|
||||
<%= if field.input_type == "checkbox" do %>
|
||||
<input type="hidden" name={field.id} value="off" />
|
||||
<input
|
||||
type="checkbox"
|
||||
name={field.id}
|
||||
|
|
@ -249,32 +251,10 @@ defmodule MvWeb.JoinLive do
|
|||
end
|
||||
end
|
||||
|
||||
defp custom_field_map(allowlist, member_field_strings) do
|
||||
custom_field_ids =
|
||||
allowlist
|
||||
|> Enum.map(& &1.id)
|
||||
|> Enum.reject(&(&1 in member_field_strings))
|
||||
|
||||
case custom_field_ids do
|
||||
[] ->
|
||||
%{}
|
||||
|
||||
ids ->
|
||||
Mv.Membership.CustomField
|
||||
|> Ash.Query.select([:id, :name, :value_type])
|
||||
|> Ash.read(domain: Mv.Membership, authorize?: false)
|
||||
|> case do
|
||||
{:ok, fields} ->
|
||||
allowed_ids = MapSet.new(ids)
|
||||
|
||||
fields
|
||||
|> Enum.filter(&MapSet.member?(allowed_ids, &1.id))
|
||||
|> Map.new(&{&1.id, &1})
|
||||
|
||||
{:error, _} ->
|
||||
%{}
|
||||
end
|
||||
end
|
||||
defp custom_field_map(allowlist, _member_field_strings) do
|
||||
allowlist
|
||||
|> Enum.map(& &1.id)
|
||||
|> CustomFieldLookup.fetch_map_by_ids(authorize?: false, select: [:id, :name, :value_type])
|
||||
end
|
||||
|
||||
defp initial_form_params(join_fields) do
|
||||
|
|
@ -342,9 +322,12 @@ defmodule MvWeb.JoinLive do
|
|||
}
|
||||
|
||||
form_data =
|
||||
params
|
||||
|> Enum.filter(fn {key, _} -> key in allowlist_ids and key not in typed end)
|
||||
|> Map.new(fn {k, v} -> {k, String.trim(to_string(v))} end)
|
||||
join_fields
|
||||
|> Enum.filter(&(&1.id not in typed))
|
||||
|> Map.new(fn field ->
|
||||
{field.id, normalize_join_field_value(params[field.id], field.input_type)}
|
||||
end)
|
||||
|> Map.take(MapSet.to_list(allowlist_ids))
|
||||
|
||||
attrs = %{attrs | form_data: form_data}
|
||||
{:ok, attrs}
|
||||
|
|
@ -356,6 +339,10 @@ defmodule MvWeb.JoinLive do
|
|||
if is_binary(v), do: String.trim(v), else: nil
|
||||
end
|
||||
|
||||
defp normalize_join_field_value(raw, _input_type) when is_binary(raw), do: String.trim(raw)
|
||||
defp normalize_join_field_value(_raw, "checkbox"), do: "off"
|
||||
defp normalize_join_field_value(_raw, _input_type), do: ""
|
||||
|
||||
# Prefer X-Forwarded-For / X-Real-IP when behind a reverse proxy; fall back to peer_data.
|
||||
# Uses :inet.ntoa/1 for correct IPv4 and IPv6 string representation.
|
||||
defp client_ip_from_socket(socket) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue