- Bug #12: Lower rate limit to 15/min - Bug #13: Wrap model loading in Task.start - Bug #14: Fix classify_time_period guard gap at -3.0 - Bug #15: Not applicable (Elixir has no ?? operator) - Bug #16: Remove fallback Repo.get for station preload - Bug #17: Extract cache_key() in ContactMapController - Bug #18: Add has_many :contacts and :beacons to User schema - A&D #4: Move serve_markdown_if_requested after secure headers - Config #1: Move signing_salt to runtime.exs env var - Config #2: Use --check-unused instead of --unused - Config #3: Re-enable UnsafeToAtom Credo check - Config #5: Re-enable LeakyEnvironment Credo check - Add @spec annotations to fix re-enabled Specs violations - Replace String.to_atom with to_existing_atom where guarded
88 lines
2.3 KiB
Elixir
88 lines
2.3 KiB
Elixir
defmodule Microwaveprop.Accounts.UserNotifier do
|
|
@moduledoc false
|
|
import Swoosh.Email
|
|
|
|
alias Microwaveprop.Accounts.User
|
|
alias Microwaveprop.Mailer
|
|
|
|
# Delivers the email using the application mailer.
|
|
defp deliver(recipient, subject, body) do
|
|
email =
|
|
new()
|
|
|> to(recipient)
|
|
|> Mailer.apply_defaults()
|
|
|> subject(subject)
|
|
|> text_body(body)
|
|
|
|
with {:ok, _metadata} <- Mailer.deliver(email) do
|
|
{:ok, email}
|
|
end
|
|
end
|
|
|
|
@doc """
|
|
Deliver instructions to confirm a newly registered account.
|
|
"""
|
|
@spec deliver_confirmation_instructions(User.t(), String.t()) :: {:ok, Swoosh.Email.t()} | {:error, term()}
|
|
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 reset a forgotten password.
|
|
"""
|
|
@spec deliver_reset_password_instructions(User.t(), String.t()) :: {:ok, Swoosh.Email.t()} | {:error, term()}
|
|
def deliver_reset_password_instructions(user, url) do
|
|
deliver(user.email, "Reset your NTMS Propagation password", """
|
|
|
|
==============================
|
|
|
|
Hi #{user.callsign},
|
|
|
|
Someone requested a password reset for your NTMS Propagation
|
|
account. To pick a new password, visit the URL below:
|
|
|
|
#{url}
|
|
|
|
This link expires in 24 hours. If you didn't request this,
|
|
please ignore this message — your password won't change.
|
|
|
|
==============================
|
|
""")
|
|
end
|
|
|
|
@doc """
|
|
Deliver instructions to update a user email.
|
|
"""
|
|
@spec deliver_update_email_instructions(User.t(), String.t()) :: {:ok, Swoosh.Email.t()} | {:error, term()}
|
|
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
|