|
|
|
@ -3,9 +3,7 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
Handles emails sent to users. |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
use Bamboo.Phoenix, view: Mobilizon.Web.EmailView |
|
|
|
|
|
|
|
|
|
import Bamboo.Phoenix |
|
|
|
|
use Phoenix.Swoosh, view: Mobilizon.Web.EmailView |
|
|
|
|
|
|
|
|
|
import Mobilizon.Web.Gettext, only: [gettext: 2] |
|
|
|
|
|
|
|
|
@ -17,7 +15,7 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
|
|
|
|
|
require Logger |
|
|
|
|
|
|
|
|
|
@spec confirmation_email(User.t(), String.t()) :: Bamboo.Email.t() |
|
|
|
|
@spec confirmation_email(User.t(), String.t()) :: Swoosh.Email.t() |
|
|
|
|
def confirmation_email( |
|
|
|
|
%User{email: email, confirmation_token: confirmation_token}, |
|
|
|
|
locale \\ "en" |
|
|
|
@ -30,15 +28,17 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
instance: Config.instance_name() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Email.base_email(to: email, subject: subject) |
|
|
|
|
|> assign(:locale, locale) |
|
|
|
|
|> assign(:token, confirmation_token) |
|
|
|
|
|> assign(:subject, subject) |
|
|
|
|
|> assign(:offer_unsupscription, false) |
|
|
|
|
|> render(:registration_confirmation) |
|
|
|
|
[to: email, subject: subject] |
|
|
|
|
|> Email.base_email() |
|
|
|
|
|> render_body(:registration_confirmation, %{ |
|
|
|
|
locale: locale, |
|
|
|
|
token: confirmation_token, |
|
|
|
|
subject: subject, |
|
|
|
|
offer_unsupscription: false |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec reset_password_email(User.t(), String.t()) :: Bamboo.Email.t() |
|
|
|
|
@spec reset_password_email(User.t(), String.t()) :: Swoosh.Email.t() |
|
|
|
|
def reset_password_email( |
|
|
|
|
%User{email: email, reset_password_token: reset_password_token}, |
|
|
|
|
locale \\ "en" |
|
|
|
@ -51,12 +51,14 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
instance: Config.instance_name() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Email.base_email(to: email, subject: subject) |
|
|
|
|
|> assign(:locale, locale) |
|
|
|
|
|> assign(:token, reset_password_token) |
|
|
|
|
|> assign(:subject, subject) |
|
|
|
|
|> assign(:offer_unsupscription, false) |
|
|
|
|
|> render(:password_reset) |
|
|
|
|
[to: email, subject: subject] |
|
|
|
|
|> Email.base_email() |
|
|
|
|
|> render_body(:password_reset, %{ |
|
|
|
|
locale: locale, |
|
|
|
|
token: reset_password_token, |
|
|
|
|
subject: subject, |
|
|
|
|
offer_unsupscription: false |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec check_confirmation_token(String.t()) :: |
|
|
|
@ -88,18 +90,18 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
{:ok, user} <- |
|
|
|
|
Users.update_user(user, %{ |
|
|
|
|
"confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) |
|
|
|
|
}), |
|
|
|
|
%Bamboo.Email{} <- send_confirmation_email(user, locale) do |
|
|
|
|
}) do |
|
|
|
|
send_confirmation_email(user, locale) |
|
|
|
|
Logger.info("Sent confirmation email again to #{user.email}") |
|
|
|
|
{:ok, user.email} |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec send_confirmation_email(User.t(), String.t()) :: Bamboo.Email.t() |
|
|
|
|
@spec send_confirmation_email(User.t(), String.t()) :: Swoosh.Email.t() |
|
|
|
|
def send_confirmation_email(%User{} = user, locale \\ "en") do |
|
|
|
|
user |
|
|
|
|
|> Email.User.confirmation_email(locale) |
|
|
|
|
|> Email.Mailer.send_email_later() |
|
|
|
|
|> Email.Mailer.send_email() |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@ -135,12 +137,12 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
"reset_password_token" => Crypto.random_string(30), |
|
|
|
|
"reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second) |
|
|
|
|
}) |
|
|
|
|
), |
|
|
|
|
%Bamboo.Email{} = mail <- |
|
|
|
|
user_updated |
|
|
|
|
|> Email.User.reset_password_email(locale) |
|
|
|
|
|> Email.Mailer.send_email_later() do |
|
|
|
|
{:ok, mail} |
|
|
|
|
) do |
|
|
|
|
user_updated |
|
|
|
|
|> Email.User.reset_password_email(locale) |
|
|
|
|
|> Email.Mailer.send_email() |
|
|
|
|
|
|
|
|
|
{:ok, user.email} |
|
|
|
|
else |
|
|
|
|
{:error, reason} -> {:error, reason} |
|
|
|
|
end |
|
|
|
@ -159,12 +161,14 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
instance: Config.instance_name() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Email.base_email(to: email, subject: subject) |
|
|
|
|
|> assign(:locale, user_locale) |
|
|
|
|
|> assign(:subject, subject) |
|
|
|
|
|> assign(:new_email, unconfirmed_email) |
|
|
|
|
|> assign(:offer_unsupscription, false) |
|
|
|
|
|> render(:email_changed_old) |
|
|
|
|
[to: email, subject: subject] |
|
|
|
|
|> Email.base_email() |
|
|
|
|
|> render_body(:email_changed_old, %{ |
|
|
|
|
locale: user_locale, |
|
|
|
|
new_email: unconfirmed_email, |
|
|
|
|
subject: subject, |
|
|
|
|
offer_unsupscription: false |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def send_email_reset_new_email(%User{ |
|
|
|
@ -180,12 +184,14 @@ defmodule Mobilizon.Web.Email.User do
|
|
|
|
|
instance: Config.instance_name() |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
Email.base_email(to: unconfirmed_email, subject: subject) |
|
|
|
|
|> assign(:locale, user_locale) |
|
|
|
|
|> assign(:subject, subject) |
|
|
|
|
|> assign(:token, confirmation_token) |
|
|
|
|
|> assign(:offer_unsupscription, false) |
|
|
|
|
|> render(:email_changed_new) |
|
|
|
|
[to: unconfirmed_email, subject: subject] |
|
|
|
|
|> Email.base_email() |
|
|
|
|
|> render_body(:email_changed_new, %{ |
|
|
|
|
locale: user_locale, |
|
|
|
|
token: confirmation_token, |
|
|
|
|
subject: subject, |
|
|
|
|
offer_unsupscription: false |
|
|
|
|
}) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@spec we_can_send_email(User.t()< |