defmodule Mixer.Accounts.User.Senders.SendMagicLinkEmail do @moduledoc """ Sends a magic link email """ use AshAuthentication.Sender use MixerWeb, :verified_routes import Swoosh.Email alias Mixer.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, then the user does not yet exist. email = case user_or_email do %{email: email} -> email email -> email end new() |> from({"noreply", "noreply@jimweaver.com"}) |> to(to_string(email)) |> subject("Your login link") |> html_body(body(token: token, email: email)) |> Mailer.deliver!() end defp body(params) do # NOTE: You may have to change this to match your magic link acceptance URL. link = url(~p"/magic_link/#{params[:token]}") email_template( "Your magic link", "Hello, #{params[:email]}!", """
Use the button below to sign in to Mixer. This link is valid for a short time and can only be used once.
If you didn't request this, you can safely ignore this email.
""", link, "Sign In to Mixer" ) end defp email_template(title, greeting, content, button_url, button_label) do """
|