From afad3a997a41c47b74c02db352998bcad7bf61cb Mon Sep 17 00:00:00 2001 From: Buck Doyle Date: Sun, 21 Jul 2024 18:26:53 -0500 Subject: [PATCH] Add registration emails on OAuth signup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a copy and only manually tested… ugh --- registrations/config/config.exs | 3 ++ .../pow_assent/user_identities.ex | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 registrations/lib/registrations_web/pow_assent/user_identities.ex 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