Skip to content

Commit

Permalink
Change snake_case auth URLs to kebab-case (#5979)
Browse files Browse the repository at this point in the history
  • Loading branch information
glhrmv authored Nov 26, 2024
1 parent 12778ac commit 394e501
Show file tree
Hide file tree
Showing 32 changed files with 180 additions and 180 deletions.
6 changes: 3 additions & 3 deletions lib/mix/tasks/phx.gen.auth/injector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.Injector do
Menu code to inject into the application layout template.
"""
def app_layout_menu_code_to_inject(%Schema{} = schema, padding \\ 4, newline \\ "\n") do
already_injected_str = "#{schema.route_prefix}/log_in"
already_injected_str = "#{schema.route_prefix}/log-in"

base_tailwind_classes = "text-[0.8125rem] leading-6 text-zinc-900"
link_tailwind_classes = "#{base_tailwind_classes} font-semibold hover:text-zinc-700"
Expand All @@ -182,7 +182,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.Injector do
</li>
<li>
<.link
href={~p"#{schema.route_prefix}/log_out"}
href={~p"#{schema.route_prefix}/log-out"}
method="delete"
class="#{link_tailwind_classes}"
>
Expand All @@ -200,7 +200,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth.Injector do
</li>
<li>
<.link
href={~p"#{schema.route_prefix}/log_in"}
href={~p"#{schema.route_prefix}/log-in"}
class="#{link_tailwind_classes}"
>
Log in
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ defmodule <%= inspect auth_module %> do
socket =
socket
|> Phoenix.LiveView.put_flash(:error, "You must log in to access this page.")
|> Phoenix.LiveView.redirect(to: ~p"<%= schema.route_prefix %>/log_in")
|> Phoenix.LiveView.redirect(to: ~p"<%= schema.route_prefix %>/log-in")

{:halt, socket}
end
Expand Down Expand Up @@ -208,7 +208,7 @@ defmodule <%= inspect auth_module %> do
conn
|> put_flash(:error, "You must log in to access this page.")
|> maybe_store_return_to()
|> redirect(to: ~p"<%= schema.route_prefix %>/log_in")
|> redirect(to: ~p"<%= schema.route_prefix %>/log-in")
|> halt()
end
end
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/auth_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ defmodule <%= inspect auth_module %>Test do
conn = conn |> fetch_flash() |> <%= inspect schema.alias %>Auth.require_authenticated_<%= schema.singular %>([])
assert conn.halted

assert redirected_to(conn) == ~p"<%= schema.route_prefix %>/log_in"
assert redirected_to(conn) == ~p"<%= schema.route_prefix %>/log-in"

assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
"You must log in to access this page."
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/confirmation_edit.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

<p :if={!@current_<%= schema.singular %>} class="text-center mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
| <.link href={~p"<%= schema.route_prefix %>/log-in"}>Log in</.link>
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<p :if={!@current_<%= schema.singular %>} class="text-center mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
| <.link href={~p"<%= schema.route_prefix %>/log-in"}>Log in</.link>
</p>
</div>
"""
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/confirmation_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
<p :if={!@current_<%= schema.singular %>} class="text-center mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
| <.link href={~p"<%= schema.route_prefix %>/log-in"}>Log in</.link>
</p>
</div>
"""
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/confirmation_new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@

<p :if={!@current_<%= schema.singular %>} class="text-center mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
| <.link href={~p"<%= schema.route_prefix %>/log-in"}>Log in</.link>
</p>
</div>
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/context_functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
## Examples
iex> deliver_<%= schema.singular %>_update_email_instructions(<%= schema.singular %>, current_email, &url(~p"<%= schema.route_prefix %>/settings/confirm_email/#{&1}"))
iex> deliver_<%= schema.singular %>_update_email_instructions(<%= schema.singular %>, current_email, &url(~p"<%= schema.route_prefix %>/settings/confirm-email/#{&1}"))
{:ok, %{to: ..., body: ...}}

"""
Expand Down Expand Up @@ -288,7 +288,7 @@
## Examples
iex> deliver_<%= schema.singular %>_reset_password_instructions(<%= schema.singular %>, &url(~p"<%= schema.route_prefix %>/reset_password/#{&1}"))
iex> deliver_<%= schema.singular %>_reset_password_instructions(<%= schema.singular %>, &url(~p"<%= schema.route_prefix %>/reset-password/#{&1}"))
{:ok, %{to: ..., body: ...}}
"""
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/forgot_password_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
</.simple_form>
<p class="text-center text-sm mt-4">
<.link href={~p"<%= schema.route_prefix %>/register"}>Register</.link>
| <.link href={~p"<%= schema.route_prefix %>/log_in"}>Log in</.link>
| <.link href={~p"<%= schema.route_prefix %>/log-in"}>Log in</.link>
</p>
</div>
"""
Expand All @@ -35,7 +35,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
if <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>_by_email(email) do
<%= inspect context.alias %>.deliver_<%= schema.singular %>_reset_password_instructions(
<%= schema.singular %>,
&url(~p"<%= schema.route_prefix %>/reset_password/#{&1}")
&url(~p"<%= schema.route_prefix %>/reset-password/#{&1}")
)
end

Expand Down
10 changes: 5 additions & 5 deletions priv/templates/phx.gen.auth/forgot_password_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web

describe "Forgot password page" do
test "renders email page", %{conn: conn} do
{:ok, lv, html} = live(conn, ~p"<%= schema.route_prefix %>/reset_password")
{:ok, lv, html} = live(conn, ~p"<%= schema.route_prefix %>/reset-password")

assert html =~ "Forgot your password?"
assert has_element?(lv, ~s|a[href="#{~p"<%= schema.route_prefix %>/register"}"]|, "Register")
assert has_element?(lv, ~s|a[href="#{~p"<%= schema.route_prefix %>/log_in"}"]|, "Log in")
assert has_element?(lv, ~s|a[href="#{~p"<%= schema.route_prefix %>/log-in"}"]|, "Log in")
end

test "redirects if already logged in", %{conn: conn} do
result =
conn
|> log_in_<%= schema.singular %>(<%= schema.singular %>_fixture())
|> live(~p"<%= schema.route_prefix %>/reset_password")
|> live(~p"<%= schema.route_prefix %>/reset-password")
|> follow_redirect(conn, ~p"/")

assert {:ok, _conn} = result
Expand All @@ -33,7 +33,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
end

test "sends a new reset password token", %{conn: conn, <%= schema.singular %>: <%= schema.singular %>} do
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/reset_password")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/reset-password")

{:ok, conn} =
lv
Expand All @@ -48,7 +48,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
end

test "does not send reset password token if email is invalid", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/reset_password")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/reset-password")

{:ok, conn} =
lv
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/login_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
</:subtitle>
</.header>
<.simple_form for={@form} id="login_form" action={~p"<%= schema.route_prefix %>/log_in"} phx-update="ignore">
<.simple_form for={@form} id="login_form" action={~p"<%= schema.route_prefix %>/log-in"} phx-update="ignore">
<.input field={@form[:email]} type="email" label="Email" required />
<.input field={@form[:password]} type="password" label="Password" required />
<:actions>
<.input field={@form[:remember_me]} type="checkbox" label="Keep me logged in" />
<.link href={~p"<%= schema.route_prefix %>/reset_password"} class="text-sm font-semibold">
<.link href={~p"<%= schema.route_prefix %>/reset-password"} class="text-sm font-semibold">
Forgot your password?
</.link>
</:actions>
Expand Down
16 changes: 8 additions & 8 deletions priv/templates/phx.gen.auth/login_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web

describe "Log in page" do
test "renders log in page", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"<%= schema.route_prefix %>/log_in")
{:ok, _lv, html} = live(conn, ~p"<%= schema.route_prefix %>/log-in")

assert html =~ "Log in"
assert html =~ "Register"
Expand All @@ -17,7 +17,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
result =
conn
|> log_in_<%= schema.singular %>(<%= schema.singular %>_fixture())
|> live(~p"<%= schema.route_prefix %>/log_in")
|> live(~p"<%= schema.route_prefix %>/log-in")
|> follow_redirect(conn, ~p"/")

assert {:ok, _conn} = result
Expand All @@ -29,7 +29,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
password = "123456789abcd"
<%= schema.singular %> = <%= schema.singular %>_fixture(%{password: password})

{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log_in")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log-in")

form =
form(lv, "#login_form", <%= schema.singular %>: %{email: <%= schema.singular %>.email, password: password, remember_me: true})
Expand All @@ -42,7 +42,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
test "redirects to login page with a flash error if there are no valid credentials", %{
conn: conn
} do
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log_in")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log-in")

form =
form(lv, "#login_form",
Expand All @@ -53,13 +53,13 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web

assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Invalid email or password"

assert redirected_to(conn) == "<%= schema.route_prefix %>/log_in"
assert redirected_to(conn) == "<%= schema.route_prefix %>/log-in"
end
end

describe "login navigation" do
test "redirects to registration page when the Register button is clicked", %{conn: conn} do
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log_in")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log-in")

{:ok, _login_live, login_html} =
lv
Expand All @@ -73,13 +73,13 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
test "redirects to forgot password page when the Forgot Password button is clicked", %{
conn: conn
} do
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log_in")
{:ok, lv, _html} = live(conn, ~p"<%= schema.route_prefix %>/log-in")

{:ok, conn} =
lv
|> element(~s|main a:fl-contains("Forgot your password?")|)
|> render_click()
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/reset_password")
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/reset-password")

assert conn.resp_body =~ "Forgot your password?"
end
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/registration_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
conn = get(conn, ~p"<%= schema.route_prefix %>/register")
response = html_response(conn, 200)
assert response =~ "Register"
assert response =~ ~p"<%= schema.route_prefix %>/log_in"
assert response =~ ~p"<%= schema.route_prefix %>/log-in"
assert response =~ ~p"<%= schema.route_prefix %>/register"
end

Expand Down Expand Up @@ -37,7 +37,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
response = html_response(conn, 200)
assert response =~ email
assert response =~ ~p"<%= schema.route_prefix %>/settings"
assert response =~ ~p"<%= schema.route_prefix %>/log_out"
assert response =~ ~p"<%= schema.route_prefix %>/log-out"
end

test "render errors for invalid data", %{conn: conn} do
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/registration_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
Register for an account
<:subtitle>
Already registered?
<.link navigate={~p"<%= schema.route_prefix %>/log_in"} class="font-semibold text-brand hover:underline">
<.link navigate={~p"<%= schema.route_prefix %>/log-in"} class="font-semibold text-brand hover:underline">
Log in
</.link>
to your account now.
Expand All @@ -24,7 +24,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
phx-submit="save"
phx-change="validate"
phx-trigger-action={@trigger_submit}
action={~p"<%= schema.route_prefix %>/log_in?_action=registered"}
action={~p"<%= schema.route_prefix %>/log-in?_action=registered"}
method="post"
>
<.error :if={@check_errors}>
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/registration_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
lv
|> element(~s|main a:fl-contains("Log in")|)
|> render_click()
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/log_in")
|> follow_redirect(conn, ~p"<%= schema.route_prefix %>/log-in")

assert login_html =~ "Log in"
end
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.auth/registration_new.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Register for an account
<:subtitle>
Already registered?
<.link navigate={~p"<%= schema.route_prefix %>/log_in"} class="font-semibold text-brand hover:underline">
<.link navigate={~p"<%= schema.route_prefix %>/log-in"} class="font-semibold text-brand hover:underline">
Log in
</.link>
to your account now.
Expand Down
4 changes: 2 additions & 2 deletions priv/templates/phx.gen.auth/reset_password_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
if <%= schema.singular %> = <%= inspect context.alias %>.get_<%= schema.singular %>_by_email(email) do
<%= inspect context.alias %>.deliver_<%= schema.singular %>_reset_password_instructions(
<%= schema.singular %>,
&url(~p"<%= schema.route_prefix %>/reset_password/#{&1}")
&url(~p"<%= schema.route_prefix %>/reset-password/#{&1}")
)
end

Expand All @@ -36,7 +36,7 @@ defmodule <%= inspect context.web_module %>.<%= inspect Module.concat(schema.web
{:ok, _} ->
conn
|> put_flash(:info, "Password reset successfully.")
|> redirect(to: ~p"<%= schema.route_prefix %>/log_in")
|> redirect(to: ~p"<%= schema.route_prefix %>/log-in")

{:error, changeset} ->
render(conn, :edit, changeset: changeset)
Expand Down
Loading

0 comments on commit 394e501

Please sign in to comment.