Generated Accounts context, User schema, and controllers via phx.gen.auth. Adapted it for password-only login with required email confirmation: - Users have callsign (unique, uppercased), name, email, password - Registration form fields: callsign, name, email, password, confirm - Magic-link login path removed; login is email + password only - After register, a confirmation email is sent and login is blocked until the account is confirmed via the token URL - Confirmation link logs the user in on first use - SMTP2GO configured as the outgoing mailer in k8s prod
72 lines
1.6 KiB
Elixir
72 lines
1.6 KiB
Elixir
defmodule Microwaveprop.Accounts.UserNotifier do
|
|
@moduledoc false
|
|
import Swoosh.Email
|
|
|
|
alias Microwaveprop.Mailer
|
|
|
|
@default_from {"NTMS Propagation", "noreply@mcintire.me"}
|
|
|
|
# Delivers the email using the application mailer.
|
|
defp deliver(recipient, subject, body) do
|
|
email =
|
|
new()
|
|
|> to(recipient)
|
|
|> from(from_address())
|
|
|> subject(subject)
|
|
|> text_body(body)
|
|
|
|
with {:ok, _metadata} <- Mailer.deliver(email) do
|
|
{:ok, email}
|
|
end
|
|
end
|
|
|
|
defp from_address do
|
|
case System.get_env("EMAIL_FROM") do
|
|
nil -> @default_from
|
|
"" -> @default_from
|
|
addr -> {"NTMS Propagation", addr}
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Deliver instructions to confirm a newly registered account.
|
|
"""
|
|
def deliver_confirmation_instructions(user, url) do
|
|
deliver(user.email, "Confirm your NTMS Propagation account", """
|
|
|
|
==============================
|
|
|
|
Hi #{user.callsign},
|
|
|
|
Welcome to the NTMS Propagation tool. To finish creating your
|
|
account, please confirm your email by visiting the URL below:
|
|
|
|
#{url}
|
|
|
|
This link expires in 24 hours. If you didn't create this account,
|
|
please ignore this message.
|
|
|
|
==============================
|
|
""")
|
|
end
|
|
|
|
@doc """
|
|
Deliver instructions to update a user email.
|
|
"""
|
|
def deliver_update_email_instructions(user, url) do
|
|
deliver(user.email, "Update email instructions", """
|
|
|
|
==============================
|
|
|
|
Hi #{user.email},
|
|
|
|
You can change your email by visiting the URL below:
|
|
|
|
#{url}
|
|
|
|
If you didn't request this change, please ignore this.
|
|
|
|
==============================
|
|
""")
|
|
end
|
|
end
|