Skip to content

Commit

Permalink
fix: credo
Browse files Browse the repository at this point in the history
  • Loading branch information
barnabasJ committed Nov 12, 2024
1 parent 88e9d8f commit a86ac37
Showing 1 changed file with 102 additions and 99 deletions.
201 changes: 102 additions & 99 deletions lib/mix/tasks/ash_authentication.add_strategy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -314,54 +314,55 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_new_magic_link_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)
case Igniter.Libs.Swoosh.list_mailers(igniter) do
{igniter, [mailer]} ->
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends a magic link email
"""
Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends a magic link email
"""
use AshAuthentication.Sender
#{use_web_module}
use AshAuthentication.Sender
#{use_web_module}
import Swoosh.Email
import Swoosh.Email
alias #{inspect(mailer)}
alias #{inspect(mailer)}
@impl true
def send(user_or_email, token, _) do
# if you get a user, its for a user that already exists
# if you get an email, the user does not exist yet
@impl true
def send(user_or_email, token, _) do
# if you get a user, its for a user that already exists
# if you get an email, the user does not exist yet
email =
case user_or_email do
%{email: email} -> email
email -> email
end
email =
case user_or_email do
%{email: email} -> email
email -> email
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(email))
|> subject("Your login kink")
|> html_body(body([token: token, email: email]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(email))
|> subject("Your login kink")
|> html_body(body([token: token, email: email]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
defp body(params) do
"""
Hello, \#{params[:email]}! Click this link to sign in:
defp body(params) do
"""
Hello, \#{params[:email]}! Click this link to sign in:
\#{url(~p"/auth/user/magic_link/?token=\#{params[:token]}")}
"""
end
'''
)

\#{url(~p"/auth/user/magic_link/?token=\#{params[:token]}")}
"""
end
'''
)
else
_ ->
create_example_new_magic_link_sender(igniter, sender, options)
end
Expand Down Expand Up @@ -417,44 +418,45 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_reset_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)
case Igniter.Libs.Swoosh.list_mailers(igniter) do
{igniter, [mailer]} ->
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends a password reset email
"""
Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends a password reset email
"""
use AshAuthentication.Sender
#{use_web_module}
use AshAuthentication.Sender
#{use_web_module}
import Swoosh.Email
import Swoosh.Email
alias #{inspect(mailer)}
alias #{inspect(mailer)}
@impl true
def send(user, token, _) do
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(user.email))
|> subject("Reset your password")
|> html_body(body([token: token]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
@impl true
def send(user, token, _) do
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(user.email))
|> subject("Reset your password")
|> html_body(body([token: token]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
defp body(params) do
"""
Click this link to reset your password:
defp body(params) do
"""
Click this link to reset your password:
\#{url(~p"/password-reset/\#{params[:token]}")}
"""
end
'''
)

\#{url(~p"/password-reset/\#{params[:token]}")}
"""
end
'''
)
else
_ ->
create_example_reset_sender(igniter, sender, options)
end
Expand Down Expand Up @@ -501,44 +503,45 @@ defmodule Mix.Tasks.AshAuthentication.AddStrategy do
end

defp create_new_user_confirmation_sender(igniter, sender, options) do
with {igniter, [mailer]} <- Igniter.Libs.Swoosh.list_mailers(igniter) do
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)
case Igniter.Libs.Swoosh.list_mailers(igniter) do
{igniter, [mailer]} ->
{_web_module_exists?, use_web_module, igniter} = create_use_web_module(igniter)

Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends an email for a new user to confirm their email address.
"""
Igniter.Project.Module.create_module(
igniter,
sender,
~s'''
@moduledoc """
Sends an email for a new user to confirm their email address.
"""
use AshAuthentication.Sender
#{use_web_module}
use AshAuthentication.Sender
#{use_web_module}
import Swoosh.Email
import Swoosh.Email
alias #{inspect(mailer)}
alias #{inspect(mailer)}
@impl true
def send(user, token, _) do
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(user.email))
|> subject("Confirm your email address")
|> html_body(body([token: token]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
@impl true
def send(user, token, _) do
new()
|> from({"noreply", "noreply@example.com"}) # TODO: Replace with your email
|> to(to_string(user.email))
|> subject("Confirm your email address")
|> html_body(body([token: token]))
|> #{List.last(Module.split(mailer))}.deliver!()
end
defp body(params) do
"""
Click this link to confirm your email:
defp body(params) do
"""
Click this link to confirm your email:
\#{url(~p"/auth/user/confirm_new_user?\#{[confirm: params[:token]]}")}
"""
end
'''
)

\#{url(~p"/auth/user/confirm_new_user?\#{[confirm: params[:token]]}")}
"""
end
'''
)
else
_ ->
create_example_new_user_confirmation_sender(igniter, sender, options)
end
Expand Down

0 comments on commit a86ac37

Please sign in to comment.