diff --git a/lib/keila/contacts/schemas/form_settings.ex b/lib/keila/contacts/schemas/form_settings.ex
index 53379252..081b6536 100644
--- a/lib/keila/contacts/schemas/form_settings.ex
+++ b/lib/keila/contacts/schemas/form_settings.ex
@@ -9,6 +9,8 @@ defmodule Keila.Contacts.Form.Settings do
field(:double_opt_in_required, :boolean, default: false)
field(:double_opt_in_subject, :string)
field(:double_opt_in_markdown_body, :string)
+ field(:double_opt_in_message, :string)
+ field(:double_opt_in_url, :string)
field(:csrf_disabled, :boolean, default: true)
field(:intro_text, :string)
field(:fine_print, :string)
@@ -32,6 +34,8 @@ defmodule Keila.Contacts.Form.Settings do
:double_opt_in_required,
:double_opt_in_subject,
:double_opt_in_markdown_body,
+ :double_opt_in_message,
+ :double_opt_in_url,
:csrf_disabled,
:intro_text,
:fine_print,
diff --git a/lib/keila_web/controllers/public_form_controller.ex b/lib/keila_web/controllers/public_form_controller.ex
index a1b6c0c3..2ef002e6 100644
--- a/lib/keila_web/controllers/public_form_controller.ex
+++ b/lib/keila_web/controllers/public_form_controller.ex
@@ -39,7 +39,7 @@ defmodule KeilaWeb.PublicFormController do
{:ok, form_params = %FormParams{}} ->
conn
|> assign(:email, form_params.params[:email])
- |> render("double_opt_in_required.html")
+ |> render_double_opt_in_required_or_redirect()
{:error, changeset} ->
render_form(conn, 400, changeset, form)
@@ -88,7 +88,7 @@ defmodule KeilaWeb.PublicFormController do
{:ok, form_params = %FormParams{}} ->
conn
|> assign(:email, form_params.params[:email])
- |> render("double_opt_in_required.html")
+ |> render_double_opt_in_required_or_redirect()
{:error, changeset} ->
render_form(conn, 400, changeset, form)
@@ -102,6 +102,13 @@ defmodule KeilaWeb.PublicFormController do
end
end
+ defp render_double_opt_in_required_or_redirect(conn) do
+ case conn.assigns.form.settings.double_opt_in_url do
+ url when url not in [nil, ""] -> redirect(conn, external: url)
+ _other -> render(conn, "double_opt_in_required.html")
+ end
+ end
+
def cancel_double_opt_in(conn, %{"hmac" => hmac}) do
form = conn.assigns.form
form_params = conn.assigns.form_params
diff --git a/lib/keila_web/templates/form/edit_live.html.heex b/lib/keila_web/templates/form/edit_live.html.heex
index 6993627e..24f12d07 100644
--- a/lib/keila_web/templates/form/edit_live.html.heex
+++ b/lib/keila_web/templates/form/edit_live.html.heex
@@ -101,18 +101,6 @@
<%= text_input(fs, :intro_text, class: "text-black") %>
<% end %>
-
- <%= label(fs, :success_text, gettext("Thank you message")) %>
- <%= with_validation(fs, :success_text) do %>
- <%= text_input(fs, :success_text, class: "text-black") %>
- <% end %>
-
-
- <%= label(fs, :success_text, gettext("Success redirect URL")) %>
- <%= with_validation(fs, :success_url) do %>
- <%= url_input(fs, :success_url, class: "text-black") %>
- <% end %>
-
<%= label(fs, :fine_print, gettext("Fine print")) %>
<%= with_validation(fs, :fine_print) do %>
@@ -125,6 +113,18 @@
<%= gettext("Require captcha") %>
<% end %>
<% end %>
+
+ <%= label(fs, :success_text, gettext("Thank you message")) %>
+ <%= with_validation(fs, :success_text) do %>
+ <%= text_input(fs, :success_text, class: "text-black") %>
+ <% end %>
+
+
+ <%= label(fs, :success_text, gettext("Thank you redirect URL")) %>
+ <%= with_validation(fs, :success_url) do %>
+ <%= url_input(fs, :success_url, class: "text-black") %>
+ <% end %>
+
<%= with_validation(fs, :csrf_disabled) do %>
<%= label(fs, :csrf_disabled) do %>
<%= checkbox(fs, :csrf_disabled, class: "text-emerald-500") %>
@@ -392,7 +392,7 @@
+
+
+
+
+
+
+
+
<% end) %>
<% else %>
diff --git a/lib/keila_web/templates/public_form/double_opt_in_required.html.heex b/lib/keila_web/templates/public_form/double_opt_in_required.html.heex
index f41ac16c..fcbbb547 100644
--- a/lib/keila_web/templates/public_form/double_opt_in_required.html.heex
+++ b/lib/keila_web/templates/public_form/double_opt_in_required.html.heex
@@ -1,13 +1 @@
-
+<%= render_form_double_opt_in_required(@form, @email) %>
diff --git a/lib/keila_web/views/public_form_view.ex b/lib/keila_web/views/public_form_view.ex
index 7848c675..f267bc59 100644
--- a/lib/keila_web/views/public_form_view.ex
+++ b/lib/keila_web/views/public_form_view.ex
@@ -7,14 +7,6 @@ defmodule KeilaWeb.PublicFormView do
@form_classes "contact-form container bg-white rounded py-4 md:py-8 flex flex-col gap-4"
- defp form_class_attr(_form) do
- @form_classes
- end
-
- defp form_style_attr(form) do
- build_form_styles(form)
- end
-
defp input_styles(form) do
build_styles(%{
"background-color" => form.settings.input_bg_color,
@@ -276,10 +268,40 @@ defmodule KeilaWeb.PublicFormView do
end
end
+ def render_form_double_opt_in_required(form, email) do
+ content_tag(:div, class: @form_classes, style: build_form_styles(form)) do
+ [
+ render_h1(form),
+ render_double_opt_in_required(form, email),
+ render_fine_print(form)
+ ]
+ end
+ end
+
defp render_success(form) do
content_tag(:div, form.settings.success_text || gettext("Thank you!"), class: "text-xl")
end
+ defp render_double_opt_in_required(form, email) do
+ case form.settings.double_opt_in_message do
+ message when message not in [nil, ""] ->
+ content_tag(:p, message)
+
+ _other ->
+ [
+ content_tag(:h2, class: "text-xl") do
+ gettext("Please confirm your email")
+ end,
+ content_tag(:p) do
+ gettext(
+ "We’ve just sent an email to %{email}. Please click the link in that email to confirm your subscription.",
+ email: email
+ )
+ end
+ ]
+ end
+ end
+
def render_unsubscribe_form(form) do
form_styles = build_form_styles(form)
diff --git a/test/keila_web/controllers/public_form_controller_double_opt_in_test.exs b/test/keila_web/controllers/public_form_controller_double_opt_in_test.exs
index a22e3e38..5762bbbf 100644
--- a/test/keila_web/controllers/public_form_controller_double_opt_in_test.exs
+++ b/test/keila_web/controllers/public_form_controller_double_opt_in_test.exs
@@ -29,6 +29,24 @@ defmodule KeilaWeb.PublicFormControllerDoubleOptInTest do
args: %{"form_params_id" => form_params.id}
)
end
+
+ test "redirects to double_opt_in_url if set", %{conn: conn} do
+ {conn, project} = with_login_and_project(conn)
+
+ form =
+ insert!(:contacts_form,
+ project_id: project.id,
+ settings: %{
+ captcha_required: false,
+ double_opt_in_required: true,
+ double_opt_in_url: "https://example.com"
+ }
+ )
+
+ params = params(:contact) |> Map.delete(:project_id)
+ conn = post(conn, Routes.public_form_path(conn, :show, form.id), contact: params)
+ assert redirected_to(conn, 302) == form.settings.double_opt_in_url
+ end
end
@tag :double_opt_in