2021-08-11 06:57:23 +00:00
|
|
|
defmodule Ketbin.Accounts.UserNotifier do
|
2021-08-19 20:37:08 +00:00
|
|
|
import Swoosh.Email
|
2021-08-11 06:57:23 +00:00
|
|
|
# For simplicity, this module simply logs messages to the terminal.
|
|
|
|
# You should replace it by a proper email or notification tool, such as:
|
|
|
|
#
|
|
|
|
# * Swoosh - https://hexdocs.pm/swoosh
|
|
|
|
# * Bamboo - https://hexdocs.pm/bamboo
|
|
|
|
#
|
2021-08-19 21:30:17 +00:00
|
|
|
defp deliver(to, body, subject) do
|
2021-08-11 06:57:23 +00:00
|
|
|
require Logger
|
|
|
|
Logger.debug(body)
|
2021-08-19 20:37:08 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
Task.start(fn ->
|
|
|
|
new()
|
|
|
|
|> to(to)
|
|
|
|
|> from({"Katbin", "noreply@katb.in"})
|
|
|
|
|> subject(subject)
|
|
|
|
|> text_body(body)
|
|
|
|
|> Ketbin.Mailer.deliver()
|
|
|
|
end)
|
2021-08-19 20:37:08 +00:00
|
|
|
|
2021-08-11 06:57:23 +00:00
|
|
|
{:ok, %{to: to, body: body}}
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to confirm account.
|
|
|
|
"""
|
|
|
|
def deliver_confirmation_instructions(user, url) do
|
2021-08-19 21:30:17 +00:00
|
|
|
deliver(
|
|
|
|
user.email,
|
|
|
|
"""
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
Hi #{user.email},
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
You can confirm your account by visiting the URL below:
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
#{url}
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
If you didn't create an account with us, please ignore this.
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
|
|
|
""",
|
|
|
|
"Account confirmation"
|
|
|
|
)
|
2021-08-11 06:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to reset a user password.
|
|
|
|
"""
|
|
|
|
def deliver_reset_password_instructions(user, url) do
|
2021-08-19 21:30:17 +00:00
|
|
|
deliver(
|
|
|
|
user.email,
|
|
|
|
"""
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
Hi #{user.email},
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
You can reset your password by visiting the URL below:
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
#{url}
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
If you didn't request this change, please ignore this.
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
|
|
|
""",
|
|
|
|
"Password reset requested"
|
|
|
|
)
|
2021-08-11 06:57:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc """
|
|
|
|
Deliver instructions to update a user email.
|
|
|
|
"""
|
|
|
|
def deliver_update_email_instructions(user, url) do
|
2021-08-19 21:30:17 +00:00
|
|
|
deliver(
|
|
|
|
user.email,
|
|
|
|
"""
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
Hi #{user.email},
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
You can change your email by visiting the URL below:
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
#{url}
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
If you didn't request this change, please ignore this.
|
2021-08-11 06:57:23 +00:00
|
|
|
|
2021-08-19 21:30:17 +00:00
|
|
|
==============================
|
|
|
|
""",
|
|
|
|
"Email update requested"
|
|
|
|
)
|
2021-08-11 06:57:23 +00:00
|
|
|
end
|
|
|
|
end
|