Skip to content

Commit

Permalink
dry it up
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Nov 12, 2024
1 parent 45019a1 commit 6091fde
Showing 1 changed file with 25 additions and 45 deletions.
70 changes: 25 additions & 45 deletions lib/mix/tasks/ash_authentication.add_strategy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,7 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do

defp create_new_magic_link_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
Expand Down Expand Up @@ -353,7 +347,7 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
new()
|> from({"noreply", "[email protected]"}) # TODO: Replace with your email
|> to(to_string(email))
|> subject("Your login link")
|> subject("Your login kink")
|> html_body(body([token: token, email: email]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
Expand All @@ -374,15 +368,9 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_example_new_magic_link_sender(igniter, sender, options) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)
{web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end

example_domain = options[:user] |> Module.split() |> :lists.droplast() |> Module.concat()
example_domain = example_domain(options[:user])

real_example =
if web_module_exists? do
Expand Down Expand Up @@ -430,13 +418,7 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do

defp create_reset_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
Expand Down Expand Up @@ -479,15 +461,9 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_example_reset_sender(igniter, sender, options) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end
{web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

example_domain = options[:user] |> Module.split() |> :lists.droplast() |> Module.concat()
example_domain = example_domain(options[:user])

real_example =
if web_module_exists? do
Expand Down Expand Up @@ -526,13 +502,7 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do

defp create_new_user_confirmation_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
Expand Down Expand Up @@ -575,13 +545,7 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_example_new_user_confirmation_sender(igniter, sender, options) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end
{web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

example_domain = options[:user] |> Module.split() |> :lists.droplast() |> Module.concat()

Expand Down Expand Up @@ -620,6 +584,22 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
)
end

defp create_use_web_module(igniter) do
web_module = Igniter.Libs.Phoenix.web_module(igniter)
{web_module_exists?, igniter} = Igniter.Project.Module.module_exists(igniter, web_module)

use_web_module =
if web_module_exists? do
"use #{inspect(web_module)}, :verified_routes"
end

{web_module_exists?, use_web_module, igniter}
end

defp example_domain(user) do
user |> Module.split() |> :lists.droplast() |> Module.concat()
end

defp generate_sign_in_and_registration(igniter, options) do
igniter
|> Ash.Resource.Igniter.add_new_action(options[:user], :sign_in_with_password, """
Expand Down

0 comments on commit 6091fde

Please sign in to comment.