fix(backend): handle email not being sent when resending registration instructions

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-08-17 10:35:03 +02:00
parent 52b3e5b151
commit b2492a3870
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 22 additions and 5 deletions

View File

@ -302,6 +302,9 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
{:error, :invalid_email} ->
{:error, dgettext("errors", "This email doesn't seem to be valid")}
{:error, :failed_sending_mail} ->
{:error, dgettext("errors", "Couldn't send an email. Internal error.")}
{:error, :email_too_soon} ->
{:error,
dgettext(

View File

@ -4,10 +4,18 @@ defmodule Mobilizon.Web.Email.Mailer do
"""
use Swoosh.Mailer, otp_app: :mobilizon
alias Mobilizon.Service.ErrorReporting.Sentry
require Logger
@spec send_email(Swoosh.Email.t()) :: {:ok, term} | {:error, term}
def send_email(email) do
Mobilizon.Web.Email.Mailer.deliver(email)
Logger.debug(
"Mailer options #{inspect(Keyword.drop(Application.get_env(:mobilizon, Mobilizon.Web.Email.Mailer), [:tls_options]))}"
)
Logger.debug("Sending mail, #{inspect(email)}")
res = Mobilizon.Web.Email.Mailer.deliver(email)
Logger.debug("Return from sending mail #{inspect(res)}")
res
rescue
error ->
Sentry.capture_exception(error,

View File

@ -91,13 +91,19 @@ defmodule Mobilizon.Web.Email.User do
Users.update_user(user, %{
"confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
}) do
send_confirmation_email(user, locale)
Logger.info("Sent confirmation email again to #{user.email}")
{:ok, user.email}
case send_confirmation_email(user, locale) do
{:ok, _} ->
Logger.info("Sent confirmation email again to #{user.email}")
{:ok, user.email}
{:error, err} ->
Logger.error("Failed sending email to #{user.email}. #{inspect(err)}")
{:error, :failed_sending_mail}
end
end
end
@spec send_confirmation_email(User.t(), String.t()) :: Swoosh.Email.t()
@spec send_confirmation_email(User.t(), String.t()) :: {:ok, term} | {:error, term}
def send_confirmation_email(%User{} = user, locale \\ "en") do
user
|> Email.User.confirmation_email(locale)