2019-09-17 00:45:32 +00:00
|
|
|
defmodule MobilizonWeb.Email.User do
|
2018-07-04 15:16:02 +00:00
|
|
|
@moduledoc """
|
2019-09-07 21:58:53 +00:00
|
|
|
Handles emails sent to users.
|
2018-07-04 15:16:02 +00:00
|
|
|
"""
|
2018-07-04 12:29:17 +00:00
|
|
|
|
2019-09-17 00:45:32 +00:00
|
|
|
use Bamboo.Phoenix, view: MobilizonWeb.EmailView
|
2019-09-07 21:58:53 +00:00
|
|
|
|
|
|
|
import Bamboo.{Email, Phoenix}
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
import MobilizonWeb.Gettext
|
2018-07-04 12:29:17 +00:00
|
|
|
|
2019-09-17 00:45:32 +00:00
|
|
|
alias Mobilizon.Config
|
2019-09-07 21:58:53 +00:00
|
|
|
alias Mobilizon.Users.User
|
|
|
|
|
2019-09-17 00:45:32 +00:00
|
|
|
alias MobilizonWeb.Email
|
|
|
|
|
2019-09-07 21:58:53 +00:00
|
|
|
@spec confirmation_email(User.t(), String.t()) :: Bamboo.Email.t()
|
|
|
|
def confirmation_email(
|
|
|
|
%User{email: email, confirmation_token: confirmation_token},
|
|
|
|
locale \\ "en"
|
|
|
|
) do
|
2018-07-04 12:29:17 +00:00
|
|
|
Gettext.put_locale(locale)
|
2019-09-07 21:58:53 +00:00
|
|
|
|
|
|
|
instance_url = Config.instance_url()
|
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
|
|
|
"Mobilizon: Confirmation instructions for %{instance}",
|
|
|
|
instance: instance_url
|
|
|
|
)
|
|
|
|
|
|
|
|
Email.base_email()
|
|
|
|
|> to(email)
|
|
|
|
|> subject(subject)
|
|
|
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
|
|
|
|> assign(:token, confirmation_token)
|
2018-07-04 12:29:17 +00:00
|
|
|
|> assign(:instance, instance_url)
|
|
|
|
|> render(:registration_confirmation)
|
|
|
|
end
|
|
|
|
|
2019-09-07 21:58:53 +00:00
|
|
|
@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
|
2018-07-04 12:29:17 +00:00
|
|
|
Gettext.put_locale(locale)
|
2018-07-27 08:45:35 +00:00
|
|
|
|
2019-09-07 21:58:53 +00:00
|
|
|
instance_url = Config.instance_url()
|
|
|
|
|
|
|
|
subject =
|
2018-07-27 08:45:35 +00:00
|
|
|
gettext(
|
2018-11-06 09:30:27 +00:00
|
|
|
"Mobilizon: Reset your password on %{instance} instructions",
|
2018-07-27 08:45:35 +00:00
|
|
|
instance: instance_url
|
|
|
|
)
|
2019-09-07 21:58:53 +00:00
|
|
|
|
|
|
|
Email.base_email()
|
|
|
|
|> to(email)
|
|
|
|
|> subject(subject)
|
|
|
|
|> put_header("Reply-To", Config.instance_email_reply_to())
|
|
|
|
|> assign(:token, reset_password_token)
|
2018-07-04 12:29:17 +00:00
|
|
|
|> assign(:instance, instance_url)
|
|
|
|
|> render(:password_reset)
|
|
|
|
end
|
|
|
|
end
|