diff --git a/priv/templates/phx.gen.auth/context_functions.ex b/priv/templates/phx.gen.auth/context_functions.ex index 2f9b1bed3a..cb340fed19 100644 --- a/priv/templates/phx.gen.auth/context_functions.ex +++ b/priv/templates/phx.gen.auth/context_functions.ex @@ -146,7 +146,7 @@ Ecto.Multi.new() |> Ecto.Multi.update(:<%= schema.singular %>, changeset) - |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, [context])) + |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, [context])) end @doc ~S""" @@ -199,7 +199,7 @@ Ecto.Multi.new() |> Ecto.Multi.update(:<%= schema.singular %>, changeset) - |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all)) + |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all)) |> Repo.transaction() |> case do {:ok, %{<%= schema.singular %>: <%= schema.singular %>}} -> {:ok, <%= schema.singular %>} @@ -230,7 +230,7 @@ Deletes the signed token with the given context. """ def delete_<%= schema.singular %>_session_token(token) do - Repo.delete_all(<%= inspect schema.alias %>Token.token_and_context_query(token, "session")) + Repo.delete_all(<%= inspect schema.alias %>Token.by_token_and_context_query(token, "session")) :ok end @@ -278,7 +278,7 @@ defp confirm_<%= schema.singular %>_multi(<%= schema.singular %>) do Ecto.Multi.new() |> Ecto.Multi.update(:<%= schema.singular %>, <%= inspect schema.alias %>.confirm_changeset(<%= schema.singular %>)) - |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, ["confirm"])) + |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, ["confirm"])) end ## Reset password @@ -335,7 +335,7 @@ def reset_<%= schema.singular %>_password(<%= schema.singular %>, attrs) do Ecto.Multi.new() |> Ecto.Multi.update(:<%= schema.singular %>, <%= inspect schema.alias %>.password_changeset(<%= schema.singular %>, attrs)) - |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all)) + |> Ecto.Multi.delete_all(:tokens, <%= inspect schema.alias %>Token.by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all)) |> Repo.transaction() |> case do {:ok, %{<%= schema.singular %>: <%= schema.singular %>}} -> {:ok, <%= schema.singular %>} diff --git a/priv/templates/phx.gen.auth/schema_token.ex b/priv/templates/phx.gen.auth/schema_token.ex index 71bdc954ac..b0b946867b 100644 --- a/priv/templates/phx.gen.auth/schema_token.ex +++ b/priv/templates/phx.gen.auth/schema_token.ex @@ -58,7 +58,7 @@ defmodule <%= inspect schema.module %>Token do """ def verify_session_token_query(token) do query = - from token in token_and_context_query(token, "session"), + from token in by_token_and_context_query(token, "session"), join: <%= schema.singular %> in assoc(token, :<%= schema.singular %>), where: token.inserted_at > ago(@session_validity_in_days, "day"), select: <%= schema.singular %> @@ -116,7 +116,7 @@ defmodule <%= inspect schema.module %>Token do days = days_for_context(context) query = - from token in token_and_context_query(hashed_token, context), + from token in by_token_and_context_query(hashed_token, context), join: <%= schema.singular %> in assoc(token, :<%= schema.singular %>), where: token.inserted_at > ago(^days, "day") and token.sent_to == <%= schema.singular %>.email, select: <%= schema.singular %> @@ -151,7 +151,7 @@ defmodule <%= inspect schema.module %>Token do hashed_token = :crypto.hash(@hash_algorithm, decoded_token) query = - from token in token_and_context_query(hashed_token, context), + from token in by_token_and_context_query(hashed_token, context), where: token.inserted_at > ago(@change_email_validity_in_days, "day") {:ok, query} @@ -164,18 +164,18 @@ defmodule <%= inspect schema.module %>Token do @doc """ Returns the token struct for the given token value and context. """ - def token_and_context_query(token, context) do + def by_token_and_context_query(token, context) do from <%= inspect schema.alias %>Token, where: [token: ^token, context: ^context] end @doc """ Gets all tokens for the given <%= schema.singular %> for the given contexts. """ - def <%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all) do + def by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, :all) do from t in <%= inspect schema.alias %>Token, where: t.<%= schema.singular %>_id == ^<%= schema.singular %>.id end - def <%= schema.singular %>_and_contexts_query(<%= schema.singular %>, [_ | _] = contexts) do + def by_<%= schema.singular %>_and_contexts_query(<%= schema.singular %>, [_ | _] = contexts) do from t in <%= inspect schema.alias %>Token, where: t.<%= schema.singular %>_id == ^<%= schema.singular %>.id and t.context in ^contexts end end