forked from potsda.mn/mobilizon
fix(backend): handle email not being sent when resending registration instructions
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
52b3e5b151
commit
b2492a3870
|
@ -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(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue