2019-09-17 02:45:32 +02:00
|
|
|
defmodule MobilizonWeb.Email.User do
|
2018-07-04 17:16:02 +02:00
|
|
|
@moduledoc """
|
2019-09-07 23:58:53 +02:00
|
|
|
Handles emails sent to users.
|
2018-07-04 17:16:02 +02:00
|
|
|
"""
|
2018-07-04 14:29:17 +02:00
|
|
|
|
2019-09-17 02:45:32 +02:00
|
|
|
use Bamboo.Phoenix, view: MobilizonWeb.EmailView
|
2019-09-07 23:58:53 +02:00
|
|
|
|
2019-09-23 19:33:58 +02:00
|
|
|
import Bamboo.Phoenix
|
2019-09-07 23:58:53 +02:00
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
import MobilizonWeb.Gettext
|
2018-07-04 14:29:17 +02:00
|
|
|
|
2019-09-17 02:45:32 +02:00
|
|
|
alias Mobilizon.Config
|
2019-09-07 23:58:53 +02:00
|
|
|
alias Mobilizon.Users.User
|
|
|
|
|
2019-09-17 02:45:32 +02:00
|
|
|
alias MobilizonWeb.Email
|
|
|
|
|
2019-09-07 23:58:53 +02: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 14:29:17 +02:00
|
|
|
Gettext.put_locale(locale)
|
2019-09-07 23:58:53 +02:00
|
|
|
|
|
|
|
subject =
|
|
|
|
gettext(
|
2019-09-23 19:33:58 +02:00
|
|
|
"Instructions to confirm your Mobilizon account on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
2019-09-07 23:58:53 +02:00
|
|
|
)
|
|
|
|
|
2019-09-23 19:33:58 +02:00
|
|
|
Email.base_email(to: email, subject: subject)
|
|
|
|
|> assign(:locale, locale)
|
2019-09-07 23:58:53 +02:00
|
|
|
|> assign(:token, confirmation_token)
|
2019-09-23 19:33:58 +02:00
|
|
|
|> assign(:subject, subject)
|
2019-09-24 12:09:43 +02:00
|
|
|
|> render(:registration_confirmation)
|
2018-07-04 14:29:17 +02:00
|
|
|
end
|
|
|
|
|
2019-09-07 23:58:53 +02: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 14:29:17 +02:00
|
|
|
Gettext.put_locale(locale)
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2019-09-07 23:58:53 +02:00
|
|
|
subject =
|
2018-07-27 10:45:35 +02:00
|
|
|
gettext(
|
2019-09-23 19:33:58 +02:00
|
|
|
"Instructions to reset your password on %{instance}",
|
|
|
|
instance: Config.instance_name()
|
2018-07-27 10:45:35 +02:00
|
|
|
)
|
2019-09-07 23:58:53 +02:00
|
|
|
|
2019-09-23 19:33:58 +02:00
|
|
|
Email.base_email(to: email, subject: subject)
|
|
|
|
|> assign(:locale, locale)
|
2019-09-07 23:58:53 +02:00
|
|
|
|> assign(:token, reset_password_token)
|
2019-09-23 19:33:58 +02:00
|
|
|
|> assign(:subject, subject)
|
2019-09-24 12:09:43 +02:00
|
|
|
|> render(:password_reset)
|
2018-07-04 14:29:17 +02:00
|
|
|
end
|
|
|
|
end
|