diff --git a/registrations/config/config.exs b/registrations/config/config.exs index 3293977f..b353d543 100644 --- a/registrations/config/config.exs +++ b/registrations/config/config.exs @@ -46,6 +46,9 @@ config :registrations, :pow, messages_backend: RegistrationsWeb.Pow.Messages, users_context: RegistrationsWeb.Pow.Users +config :registrations, :pow_assent, + user_identities_context: RegistrationsWeb.PowAssent.UserIdentities + # Configure phoenix generators config :phoenix, :generators, migration: true, diff --git a/registrations/lib/registrations_web/pow_assent/user_identities.ex b/registrations/lib/registrations_web/pow_assent/user_identities.ex new file mode 100644 index 00000000..39c7a759 --- /dev/null +++ b/registrations/lib/registrations_web/pow_assent/user_identities.ex @@ -0,0 +1,32 @@ +defmodule RegistrationsWeb.PowAssent.UserIdentities do + use PowAssent.Ecto.UserIdentities.Context, + repo: Registrations.Repo, + user: RegistrationsWeb.User + + import Ecto.Query, only: [from: 2] + + def create_user(user_identity_params, user_params, user_id_params) do + case pow_assent_create_user(user_identity_params, user_params, user_id_params) do + {:ok, user} -> + messages = + Registrations.Repo.all( + from(m in RegistrationsWeb.Message, + where: m.ready == true, + select: m, + order_by: :postmarked_at + ) + ) + + unless Enum.empty?(messages) do + Registrations.Mailer.send_backlog(messages, user) + end + + Registrations.Mailer.send_welcome_email(user.email) + Registrations.Mailer.send_registration(user) + {:ok, user} + + {:error, changeset} -> + {:error, changeset} + end + end +end