Fixes for Bamboo 2.0

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-09 11:56:09 +01:00
parent d782ee37f0
commit aa2c79d312
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 11 additions and 10 deletions

View File

@ -117,8 +117,9 @@ defmodule Mobilizon.GraphQL.Resolvers.User do
@spec create_user(any, map, any) :: tuple
def create_user(_parent, args, _resolution) do
with :registration_ok <- check_registration_config(args),
{:ok, %User{} = user} <- Users.register(args) do
Email.User.send_confirmation_email(user, Map.get(args, :locale, "en"))
{:ok, %User{} = user} <- Users.register(args),
{:ok, %Bamboo.Email{}} <-
Email.User.send_confirmation_email(user, Map.get(args, :locale, "en")) do
{:ok, user}
else
:registration_closed ->

View File

@ -79,13 +79,14 @@ defmodule Mobilizon.Web.Email.User do
{:ok, user} <-
Users.update_user(user, %{
"confirmation_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
}) do
send_confirmation_email(user, locale)
}),
{:ok, %Bamboo.Email{}} <- send_confirmation_email(user, locale) do
Logger.info("Sent confirmation email again to #{user.email}")
{:ok, user.email}
end
end
@spec send_confirmation_email(User.t(), String.t()) :: {:ok, Bamboo.Email.t()} | {:error, any()}
def send_confirmation_email(%User{} = user, locale \\ "en") do
user
|> Email.User.confirmation_email(locale)
@ -130,12 +131,11 @@ defmodule Mobilizon.Web.Email.User do
"reset_password_token" => Crypto.random_string(30),
"reset_password_sent_at" => DateTime.utc_now() |> DateTime.truncate(:second)
})
) do
mail =
),
{:ok, %Bamboo.Email{} = mail} <-
user_updated
|> Email.User.reset_password_email(locale)
|> Email.Mailer.deliver_later()
|> Email.Mailer.deliver_later() do
{:ok, mail}
else
{:error, reason} -> {:error, reason}