feat: add legal notice links for terms and privacy policy on registration page

This commit is contained in:
Alex Lion
2026-04-27 17:17:26 +02:00
parent 7ff3e8d634
commit af53f14879
5 changed files with 112 additions and 21 deletions

View File

@@ -75,6 +75,10 @@ MAIL_FROM_NAME=Claper
# GS_JPG_RESOLUTION=300x300 # GS_JPG_RESOLUTION=300x300
# LANGUAGES=en,fr,es,it,nl,de # LANGUAGES=en,fr,es,it,nl,de
# == Legal links shown on the registration page (both must be set to display the notice)
# TERMS_URL=https://example.com/terms
# PRIVACY_URL=https://example.com/privacy
# == Reverse proxy / IP forwarding (set these if Claper runs behind a load balancer or reverse proxy) # == Reverse proxy / IP forwarding (set these if Claper runs behind a load balancer or reverse proxy)
# Comma-separated list of trusted proxy IPs or CIDR ranges whose forwarding headers will be trusted # Comma-separated list of trusted proxy IPs or CIDR ranges whose forwarding headers will be trusted

View File

@@ -164,6 +164,31 @@ allow_unlink_external_provider =
logout_redirect_url = get_var_from_path_or_env(config_dir, "LOGOUT_REDIRECT_URL", nil) logout_redirect_url = get_var_from_path_or_env(config_dir, "LOGOUT_REDIRECT_URL", nil)
normalize_url = fn
nil ->
nil
value ->
case String.trim(value) do
"" -> nil
trimmed -> trimmed
end
end
terms_url = normalize_url.(get_var_from_path_or_env(config_dir, "TERMS_URL", nil))
privacy_url = normalize_url.(get_var_from_path_or_env(config_dir, "PRIVACY_URL", nil))
for {name, value} <- [{"TERMS_URL", terms_url}, {"PRIVACY_URL", privacy_url}],
not is_nil(value) do
case URI.parse(value) do
%URI{scheme: scheme} when scheme in ["http", "https"] ->
:ok
_ ->
raise "#{name} must start with `http` or `https`. Got `#{value}`"
end
end
languages = languages =
get_var_from_path_or_env(config_dir, "LANGUAGES", "en,fr,es,it,de") get_var_from_path_or_env(config_dir, "LANGUAGES", "en,fr,es,it,de")
|> String.split(",") |> String.split(",")
@@ -210,7 +235,9 @@ config :claper,
logout_redirect_url: logout_redirect_url, logout_redirect_url: logout_redirect_url,
languages: languages, languages: languages,
remote_ip_proxies: remote_ip_proxies, remote_ip_proxies: remote_ip_proxies,
remote_ip_headers: remote_ip_headers remote_ip_headers: remote_ip_headers,
terms_url: terms_url,
privacy_url: privacy_url
config :claper, :presentations, config :claper, :presentations,
max_file_size: max_file_size, max_file_size: max_file_size,

View File

@@ -111,23 +111,31 @@
)} )}
</p> </p>
<p class="text-xs leading-6 text-gray-500"> <% terms_url = Application.get_env(:claper, :terms_url) %>
{gettext("By creating an account, you agree to our")} <% privacy_url = Application.get_env(:claper, :privacy_url) %>
{" "} <%= if terms_url && privacy_url do %>
{link(gettext("Terms of Service"), <p class="text-xs leading-6 text-gray-500">
to: ~p"/tos", {gettext("By creating an account, you agree to our")}
class: {" "}
"text-gray-300 underline decoration-gray-500 underline-offset-2 hover:text-white" {link(gettext("Terms of Service"),
)} to: terms_url,
{" "} target: "_blank",
{gettext("and")} rel: "noopener noreferrer",
{" "} class:
{link(gettext("Privacy Policy"), "text-gray-300 underline decoration-gray-500 underline-offset-2 hover:text-white"
to: ~p"/privacy", )}
class: {" "}
"text-gray-300 underline decoration-gray-500 underline-offset-2 hover:text-white" {gettext("and")}
)} . {" "}
</p> {link(gettext("Privacy Policy"),
to: privacy_url,
target: "_blank",
rel: "noopener noreferrer",
class:
"text-gray-300 underline decoration-gray-500 underline-offset-2 hover:text-white"
)} .
</p>
<% end %>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -18,9 +18,7 @@
{gettext("Pick a new password and get back to presenting.")} {gettext("Pick a new password and get back to presenting.")}
</h1> </h1>
<p class="max-w-xl text-lg leading-8 text-gray-100/90 lg:text-xl"> <p class="max-w-xl text-lg leading-8 text-gray-100/90 lg:text-xl">
{gettext( {gettext("Choose something secure that you'll remember, then you're all set.")}
"Choose something secure that you'll remember, then you're all set."
)}
</p> </p>
</div> </div>
</div> </div>

View File

@@ -8,10 +8,14 @@ defmodule ClaperWeb.UserRegistrationControllerTest do
setup do setup do
enable_account_creation = Application.get_env(:claper, :enable_account_creation) enable_account_creation = Application.get_env(:claper, :enable_account_creation)
email_confirmation = Application.get_env(:claper, :email_confirmation) email_confirmation = Application.get_env(:claper, :email_confirmation)
terms_url = Application.get_env(:claper, :terms_url)
privacy_url = Application.get_env(:claper, :privacy_url)
on_exit(fn -> on_exit(fn ->
Application.put_env(:claper, :enable_account_creation, enable_account_creation) Application.put_env(:claper, :enable_account_creation, enable_account_creation)
Application.put_env(:claper, :email_confirmation, email_confirmation) Application.put_env(:claper, :email_confirmation, email_confirmation)
Application.put_env(:claper, :terms_url, terms_url)
Application.put_env(:claper, :privacy_url, privacy_url)
end) end)
:ok :ok
@@ -48,6 +52,56 @@ defmodule ClaperWeb.UserRegistrationControllerTest do
assert redirected_to(conn) == "/events" assert redirected_to(conn) == "/events"
end end
test "shows the legal notice when both TERMS_URL and PRIVACY_URL are configured", %{
conn: conn
} do
Application.put_env(:claper, :enable_account_creation, true)
Application.put_env(:claper, :terms_url, "https://example.com/terms")
Application.put_env(:claper, :privacy_url, "https://example.com/privacy")
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
assert response =~ "By creating an account"
assert response =~ "https://example.com/terms"
assert response =~ "https://example.com/privacy"
end
test "hides the legal notice when only TERMS_URL is configured", %{conn: conn} do
Application.put_env(:claper, :enable_account_creation, true)
Application.put_env(:claper, :terms_url, "https://example.com/terms")
Application.put_env(:claper, :privacy_url, nil)
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
refute response =~ "By creating an account"
refute response =~ "https://example.com/terms"
end
test "hides the legal notice when only PRIVACY_URL is configured", %{conn: conn} do
Application.put_env(:claper, :enable_account_creation, true)
Application.put_env(:claper, :terms_url, nil)
Application.put_env(:claper, :privacy_url, "https://example.com/privacy")
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
refute response =~ "By creating an account"
refute response =~ "https://example.com/privacy"
end
test "hides the legal notice when neither URL is configured", %{conn: conn} do
Application.put_env(:claper, :enable_account_creation, true)
Application.put_env(:claper, :terms_url, nil)
Application.put_env(:claper, :privacy_url, nil)
conn = get(conn, ~p"/users/register")
response = html_response(conn, 200)
refute response =~ "By creating an account"
end
end end
describe "POST /users/register" do describe "POST /users/register" do