2023-07-28 20:44:00 +00:00
|
|
|
defmodule Prymn.Accounts.UserNotifier do
|
|
|
|
import Swoosh.Email
|
|
|
|
|
|
|
|
alias Prymn.Mailer
|
|
|
|
|
|
|
|
# Delivers the email using the application mailer.
|
|
|
|
defp deliver(recipient, subject, body) do
|
|
|
|
email =
|
|
|
|
new()
|
|
|
|
|> to(recipient)
|
|
|
|
|> from({"Prymn", "contact@example.com"})
|
|
|
|
|> subject(subject)
|
|
|
|
|> text_body(body)
|
|
|
|
|
2023-07-29 11:45:09 +00:00
|
|
|
{:ok, _metadata} = Mailer.deliver(email)
|
|
|
|
{:ok, email}
|
2023-07-28 20:44:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to confirm account.
|
|
|
|
"""
|
2023-08-29 11:16:25 +00:00
|
|
|
@spec deliver_confirmation_instructions(Prymn.Accounts.User.t(), String.t()) ::
|
|
|
|
{:ok, Swoosh.Email.t()}
|
2023-07-28 20:44:00 +00:00
|
|
|
def deliver_confirmation_instructions(user, url) do
|
|
|
|
deliver(user.email, "Confirmation instructions", """
|
|
|
|
|
|
|
|
==============================
|
|
|
|
|
|
|
|
Hi #{user.email},
|
|
|
|
|
|
|
|
You can confirm your account by visiting the URL below:
|
|
|
|
|
|
|
|
#{url}
|
|
|
|
|
|
|
|
If you didn't create an account with us, please ignore this.
|
|
|
|
|
|
|
|
==============================
|
|
|
|
""")
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to reset a user password.
|
|
|
|
"""
|
2023-08-29 11:16:25 +00:00
|
|
|
@spec deliver_reset_password_instructions(Prymn.Accounts.User.t(), String.t()) ::
|
|
|
|
{:ok, Swoosh.Email.t()}
|
2023-07-28 20:44:00 +00:00
|
|
|
def deliver_reset_password_instructions(user, url) do
|
|
|
|
deliver(user.email, "Reset password instructions", """
|
|
|
|
|
|
|
|
==============================
|
|
|
|
|
|
|
|
Hi #{user.email},
|
|
|
|
|
|
|
|
You can reset your password by visiting the URL below:
|
|
|
|
|
|
|
|
#{url}
|
|
|
|
|
|
|
|
If you didn't request this change, please ignore this.
|
|
|
|
|
|
|
|
==============================
|
|
|
|
""")
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to update a user email.
|
|
|
|
"""
|
2023-08-29 11:16:25 +00:00
|
|
|
@spec deliver_update_email_instructions(Prymn.Accounts.User.t(), String.t()) ::
|
|
|
|
{:ok, Swoosh.Email.t()}
|
2023-07-28 20:44:00 +00:00
|
|
|
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
|