From 5923608f0777caa85668a95b8be216c45f74feff Mon Sep 17 00:00:00 2001 From: SimpleTest Date: Tue, 21 Jul 2026 23:38:42 +0300 Subject: [PATCH] Separate login and registration email guidance --- .../user_registration_controller.ex | 7 +- .../user_registration_html/sent.html.heex | 118 ++++++++++++------ .../controllers/user_session_controller.ex | 2 +- .../user_registration_controller_test.exs | 22 +++- .../user_session_controller_test.exs | 4 +- 5 files changed, 100 insertions(+), 53 deletions(-) diff --git a/lib/who_need_help_web/controllers/user_registration_controller.ex b/lib/who_need_help_web/controllers/user_registration_controller.ex index 6a415cc..f32c2fa 100644 --- a/lib/who_need_help_web/controllers/user_registration_controller.ex +++ b/lib/who_need_help_web/controllers/user_registration_controller.ex @@ -14,8 +14,9 @@ defmodule WhoNeedHelpWeb.UserRegistrationController do render_registration(conn, changeset) end - def sent(conn, _params) do - render(conn, :sent) + def sent(conn, params) do + email_flow = if params["flow"] == "register", do: "register", else: "login" + render(conn, :sent, email_flow: email_flow) end def create(conn, %{"user" => user_params}) when is_map(user_params) do @@ -112,7 +113,7 @@ defmodule WhoNeedHelpWeb.UserRegistrationController do "If this address can be registered or signed in, login instructions will arrive shortly." ) ) - |> redirect(to: ~p"/users/check-email") + |> redirect(to: ~p"/users/check-email?flow=register") end defp unique_email_error?(%Ecto.Changeset{} = changeset) do diff --git a/lib/who_need_help_web/controllers/user_registration_html/sent.html.heex b/lib/who_need_help_web/controllers/user_registration_html/sent.html.heex index 756ec60..77e8030 100644 --- a/lib/who_need_help_web/controllers/user_registration_html/sent.html.heex +++ b/lib/who_need_help_web/controllers/user_registration_html/sent.html.heex @@ -1,47 +1,83 @@ -<.header> - {gettext("Check your email")} - <:subtitle> - {gettext("If the address can be used, a secure link will arrive shortly.")} - - - -
-
- <.icon name="hero-check-circle" class="mt-0.5 size-6 shrink-0" /> -
-

{gettext("Request accepted")}

-

- {gettext("The site processed your request. Follow the email instructions if they arrive.")} -

+ +
+
+ <.header> + {if @email_flow == "register", + do: gettext("Check your email to finish registration"), + else: gettext("Sign-in request processed")} + <:subtitle> + <%= if @email_flow == "register" do %> + {gettext("Use the newest confirmation link if it arrives.")} + <% else %> + {gettext("Signing in does not create a new account.")} + <% end %> + +
-
-
-
- <.icon name="hero-envelope" class="size-6" /> -
-
-

{gettext("Open the newest Who Need Help email")}

-

+

+
+ <.icon name="hero-check-circle" class="mt-0.5 size-6 shrink-0" /> +
+

+ {if @email_flow == "register", + do: gettext("Registration request accepted"), + else: gettext("Sign-in request accepted")} +

+

+ <%= if @email_flow == "register" do %> + {gettext("The site processed your registration request.")} + <% else %> + {gettext( + "If this email belongs to an existing account, a secure sign-in link will arrive shortly." + )} + <% end %> +

+
+
+ +
+
+ <.icon name="hero-envelope" class="size-6" /> +
+
+

+ <%= if @email_flow == "register" do %> + {gettext("Open the newest Who Need Help email")} + <% else %> + {gettext("Already registered? Check your email")} + <% end %> +

+

+ <%= if @email_flow == "register" do %> + {gettext( + "Use the confirmation link in the message. You do not need to enter your address again on this site." + )} + <% else %> + {gettext( + "For privacy, this page cannot reveal whether an account exists. If you are new to Who Need Help, choose Register instead." + )} + <% end %> +

+
+
+ +
{gettext( - "If a message arrives, use the secure link in it. You do not need to enter your address again on this site." + "If the message is not in your inbox after a minute, check Spam. Older secure links may have been replaced by the newest one." )} -

+
+ +
+ <.link navigate={~p"/users/log-in"} class="btn btn-primary"> + {gettext("Back to log in")} + + <.link navigate={~p"/users/register"} class="btn btn-outline"> + {if @email_flow == "register", + do: gettext("Use another email"), + else: gettext("Register instead")} + +
- -
- {gettext( - "If the message is not in your inbox after a minute, check Spam. Older confirmation links may have been replaced by the newest one." - )} -
- -
- <.link navigate={~p"/users/log-in"} class="btn btn-primary"> - {gettext("Back to log in")} - - <.link navigate={~p"/users/register"} class="btn btn-outline"> - {gettext("Register instead")} - -
-
+
diff --git a/lib/who_need_help_web/controllers/user_session_controller.ex b/lib/who_need_help_web/controllers/user_session_controller.ex index 6d37009..58ee43b 100644 --- a/lib/who_need_help_web/controllers/user_session_controller.ex +++ b/lib/who_need_help_web/controllers/user_session_controller.ex @@ -100,7 +100,7 @@ defmodule WhoNeedHelpWeb.UserSessionController do conn |> put_flash(:info, info) - |> redirect(to: ~p"/users/check-email") + |> redirect(to: ~p"/users/check-email?flow=login") {:error, :rate_limited} -> conn diff --git a/test/who_need_help_web/controllers/user_registration_controller_test.exs b/test/who_need_help_web/controllers/user_registration_controller_test.exs index ad6d74f..ce124b3 100644 --- a/test/who_need_help_web/controllers/user_registration_controller_test.exs +++ b/test/who_need_help_web/controllers/user_registration_controller_test.exs @@ -30,18 +30,28 @@ defmodule WhoNeedHelpWeb.UserRegistrationControllerTest do describe "GET /users/check-email" do test "explains that the confirmation continues from the email", %{conn: conn} do - conn = get(conn, ~p"/users/check-email") + conn = get(conn, ~p"/users/check-email?flow=login") response = html_response(conn, 200) assert get_resp_header(conn, "cache-control") == ["no-store"] - assert response =~ "Check your email" - assert response =~ "Request accepted" + assert response =~ "Sign-in request processed" + assert response =~ "Signing in does not create a new account" + assert response =~ "Sign-in request accepted" + assert response =~ "cannot reveal whether an account exists" assert response =~ ~s(role="status") - assert response =~ "You do not need to enter your address again" assert response =~ "check Spam" assert response =~ ~p"/users/log-in" assert response =~ ~p"/users/register" end + + test "renders registration-specific guidance", %{conn: conn} do + response = conn |> get(~p"/users/check-email?flow=register") |> html_response(200) + + assert response =~ "Check your email to finish registration" + assert response =~ "Registration request accepted" + assert response =~ "You do not need to enter your address again" + refute response =~ "cannot reveal whether an account exists" + end end describe "POST /users/register" do @@ -77,7 +87,7 @@ defmodule WhoNeedHelpWeb.UserRegistrationControllerTest do }) refute get_session(conn, :user_token) - assert redirected_to(conn) == ~p"/users/check-email" + assert redirected_to(conn) == ~p"/users/check-email?flow=register" assert conn.assigns.flash["info"] =~ "If this address can be registered or signed in, login instructions will arrive shortly." @@ -91,7 +101,7 @@ defmodule WhoNeedHelpWeb.UserRegistrationControllerTest do existing_conn = post(conn, ~p"/users/register", params) - assert redirected_to(existing_conn) == ~p"/users/check-email" + assert redirected_to(existing_conn) == ~p"/users/check-email?flow=register" assert existing_conn.assigns.flash["info"] == "If this address can be registered or signed in, login instructions will arrive shortly." diff --git a/test/who_need_help_web/controllers/user_session_controller_test.exs b/test/who_need_help_web/controllers/user_session_controller_test.exs index 8a5e3fd..02faf9b 100644 --- a/test/who_need_help_web/controllers/user_session_controller_test.exs +++ b/test/who_need_help_web/controllers/user_session_controller_test.exs @@ -179,7 +179,7 @@ defmodule WhoNeedHelpWeb.UserSessionControllerTest do }) assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system" - assert redirected_to(conn) == ~p"/users/check-email" + assert redirected_to(conn) == ~p"/users/check-email?flow=login" assert WhoNeedHelp.Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "login" assert_email_sent(fn email -> @@ -199,7 +199,7 @@ defmodule WhoNeedHelpWeb.UserSessionControllerTest do "user" => %{"email" => user.email} }) - assert redirected_to(conn) == ~p"/users/check-email" + assert redirected_to(conn) == ~p"/users/check-email?flow=login" refute WhoNeedHelp.Repo.get_by(Accounts.UserToken, user_id: user.id) end