mobilizon.chapril.org-mobil.../lib/mobilizon_web/email/user.ex
Thomas Citharel 6a41b13446
🎨 Add fancy html emails
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
2019-09-23 19:50:33 +02:00

59 lines
1.5 KiB
Elixir

defmodule MobilizonWeb.Email.User do
@moduledoc """
Handles emails sent to users.
"""
use Bamboo.Phoenix, view: MobilizonWeb.EmailView
import Bamboo.Phoenix
import MobilizonWeb.Gettext
alias Mobilizon.Config
alias Mobilizon.Users.User
alias MobilizonWeb.Email
@spec confirmation_email(User.t(), String.t()) :: Bamboo.Email.t()
def confirmation_email(
%User{email: email, confirmation_token: confirmation_token},
locale \\ "en"
) do
Gettext.put_locale(locale)
subject =
gettext(
"Instructions to confirm your Mobilizon account on %{instance}",
instance: Config.instance_name()
)
Email.base_email(to: email, subject: subject)
|> assign(:locale, locale)
|> assign(:token, confirmation_token)
|> assign(:subject, subject)
|> render("registration_confirmation.html")
|> Email.premail()
end
@spec reset_password_email(User.t(), String.t()) :: Bamboo.Email.t()
def reset_password_email(
%User{email: email, reset_password_token: reset_password_token},
locale \\ "en"
) do
Gettext.put_locale(locale)
subject =
gettext(
"Instructions to reset your password on %{instance}",
instance: Config.instance_name()
)
Email.base_email(to: email, subject: subject)
|> assign(:locale, locale)
|> assign(:token, reset_password_token)
|> assign(:subject, subject)
|> render("password_reset.html")
|> Email.premail()
end
end