Merge branch 'new-user-emails' into 'develop'
Basic new user registration email, various improvements See merge request pleroma/pleroma!3304
This commit is contained in:
commit
fc42e714e2
@ -52,6 +52,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
- Configurable background job limits for RichMedia (link previews) and MediaProxyWarmingPolicy
|
||||
- Ability to define custom HTTP headers per each frontend
|
||||
- MRF (`NoEmptyPolicy`): New MRF Policy which will deny empty statuses or statuses of only mentions from being created by local users
|
||||
- New users will receive a simple email confirming their registration if no other emails will be dispatched. (e.g., Welcome, Confirmation, or Approval Required)
|
||||
|
||||
<details>
|
||||
<summary>API Changes</summary>
|
||||
|
@ -38,7 +38,7 @@ defmodule Mix.Tasks.Pleroma.Email do
|
||||
invisible: false
|
||||
})
|
||||
|> Pleroma.Repo.chunk_stream(500)
|
||||
|> Stream.each(&Pleroma.User.try_send_confirmation_email(&1))
|
||||
|> Stream.each(&Pleroma.User.maybe_send_confirmation_email(&1))
|
||||
|> Stream.run()
|
||||
end
|
||||
end
|
||||
|
@ -81,9 +81,9 @@ defmodule Pleroma.Emails.UserEmail do
|
||||
)
|
||||
|
||||
html_body = """
|
||||
<h3>Welcome to #{instance_name()}!</h3>
|
||||
<h3>Thank you for registering on #{instance_name()}</h3>
|
||||
<p>Email confirmation is required to activate the account.</p>
|
||||
<p>Click the following link to proceed: <a href="#{confirmation_url}">activate your account</a>.</p>
|
||||
<p>Please click the following link to <a href="#{confirmation_url}">activate your account</a>.</p>
|
||||
"""
|
||||
|
||||
new()
|
||||
@ -106,6 +106,20 @@ defmodule Pleroma.Emails.UserEmail do
|
||||
|> html_body(html_body)
|
||||
end
|
||||
|
||||
def successful_registration_email(user) do
|
||||
html_body = """
|
||||
<h3>Hello @#{user.nickname},</h3>
|
||||
<p>Your account at #{instance_name()} has been registered successfully.</p>
|
||||
<p>No further action is required to activate your account.</p>
|
||||
"""
|
||||
|
||||
new()
|
||||
|> to(recipient(user))
|
||||
|> from(sender())
|
||||
|> subject("Account registered on #{instance_name()}")
|
||||
|> html_body(html_body)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Email used in digest email notifications
|
||||
Includes Mentions and New Followers data
|
||||
|
@ -798,7 +798,7 @@ defmodule Pleroma.User do
|
||||
end
|
||||
|
||||
def post_register_action(%User{is_confirmed: false} = user) do
|
||||
with {:ok, _} <- try_send_confirmation_email(user) do
|
||||
with {:ok, _} <- maybe_send_confirmation_email(user) do
|
||||
{:ok, user}
|
||||
end
|
||||
end
|
||||
@ -814,9 +814,10 @@ defmodule Pleroma.User do
|
||||
with {:ok, user} <- autofollow_users(user),
|
||||
{:ok, _} <- autofollowing_users(user),
|
||||
{:ok, user} <- set_cache(user),
|
||||
{:ok, _} <- send_welcome_email(user),
|
||||
{:ok, _} <- send_welcome_message(user),
|
||||
{:ok, _} <- send_welcome_chat_message(user) do
|
||||
{:ok, _} <- maybe_send_registration_email(user),
|
||||
{:ok, _} <- maybe_send_welcome_email(user),
|
||||
{:ok, _} <- maybe_send_welcome_message(user),
|
||||
{:ok, _} <- maybe_send_welcome_chat_message(user) do
|
||||
{:ok, user}
|
||||
end
|
||||
end
|
||||
@ -841,7 +842,7 @@ defmodule Pleroma.User do
|
||||
{:ok, :enqueued}
|
||||
end
|
||||
|
||||
def send_welcome_message(user) do
|
||||
defp maybe_send_welcome_message(user) do
|
||||
if User.WelcomeMessage.enabled?() do
|
||||
User.WelcomeMessage.post_message(user)
|
||||
{:ok, :enqueued}
|
||||
@ -850,7 +851,7 @@ defmodule Pleroma.User do
|
||||
end
|
||||
end
|
||||
|
||||
def send_welcome_chat_message(user) do
|
||||
defp maybe_send_welcome_chat_message(user) do
|
||||
if User.WelcomeChatMessage.enabled?() do
|
||||
User.WelcomeChatMessage.post_message(user)
|
||||
{:ok, :enqueued}
|
||||
@ -859,7 +860,7 @@ defmodule Pleroma.User do
|
||||
end
|
||||
end
|
||||
|
||||
def send_welcome_email(%User{email: email} = user) when is_binary(email) do
|
||||
defp maybe_send_welcome_email(%User{email: email} = user) when is_binary(email) do
|
||||
if User.WelcomeEmail.enabled?() do
|
||||
User.WelcomeEmail.send_email(user)
|
||||
{:ok, :enqueued}
|
||||
@ -868,10 +869,10 @@ defmodule Pleroma.User do
|
||||
end
|
||||
end
|
||||
|
||||
def send_welcome_email(_), do: {:ok, :noop}
|
||||
defp maybe_send_welcome_email(_), do: {:ok, :noop}
|
||||
|
||||
@spec try_send_confirmation_email(User.t()) :: {:ok, :enqueued | :noop}
|
||||
def try_send_confirmation_email(%User{is_confirmed: false, email: email} = user)
|
||||
@spec maybe_send_confirmation_email(User.t()) :: {:ok, :enqueued | :noop}
|
||||
def maybe_send_confirmation_email(%User{is_confirmed: false, email: email} = user)
|
||||
when is_binary(email) do
|
||||
if Config.get([:instance, :account_activation_required]) do
|
||||
send_confirmation_email(user)
|
||||
@ -881,7 +882,7 @@ defmodule Pleroma.User do
|
||||
end
|
||||
end
|
||||
|
||||
def try_send_confirmation_email(_), do: {:ok, :noop}
|
||||
def maybe_send_confirmation_email(_), do: {:ok, :noop}
|
||||
|
||||
@spec send_confirmation_email(Uset.t()) :: User.t()
|
||||
def send_confirmation_email(%User{} = user) do
|
||||
@ -892,6 +893,24 @@ defmodule Pleroma.User do
|
||||
user
|
||||
end
|
||||
|
||||
@spec maybe_send_registration_email(User.t()) :: {:ok, :enqueued | :noop}
|
||||
defp maybe_send_registration_email(%User{email: email} = user) when is_binary(email) do
|
||||
with false <- User.WelcomeEmail.enabled?(),
|
||||
false <- Config.get([:instance, :account_activation_required], false),
|
||||
false <- Config.get([:instance, :account_approval_required], false) do
|
||||
user
|
||||
|> Pleroma.Emails.UserEmail.successful_registration_email()
|
||||
|> Pleroma.Emails.Mailer.deliver_async()
|
||||
|
||||
{:ok, :enqueued}
|
||||
else
|
||||
_ ->
|
||||
{:ok, :noop}
|
||||
end
|
||||
end
|
||||
|
||||
defp maybe_send_registration_email(_), do: {:ok, :noop}
|
||||
|
||||
def needs_update?(%User{local: true}), do: false
|
||||
|
||||
def needs_update?(%User{local: false, last_refreshed_at: nil}), do: true
|
||||
|
@ -56,7 +56,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
|
||||
nickname_or_email = params[:email] || params[:nickname]
|
||||
|
||||
with %User{} = user <- User.get_by_nickname_or_email(nickname_or_email),
|
||||
{:ok, _} <- User.try_send_confirmation_email(user) do
|
||||
{:ok, _} <- User.maybe_send_confirmation_email(user) do
|
||||
json_response(conn, :no_content, "")
|
||||
end
|
||||
end
|
||||
|
@ -551,6 +551,27 @@ defmodule Pleroma.UserTest do
|
||||
)
|
||||
end
|
||||
|
||||
test "it sends a registration confirmed email if no others will be sent" do
|
||||
clear_config([:welcome, :email, :enabled], false)
|
||||
clear_config([:instance, :account_activation_required], false)
|
||||
clear_config([:instance, :account_approval_required], false)
|
||||
|
||||
{:ok, user} =
|
||||
User.register_changeset(%User{}, @full_user_data)
|
||||
|> User.register()
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
instance_name = Pleroma.Config.get([:instance, :name])
|
||||
sender = Pleroma.Config.get([:instance, :notify_email])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, sender},
|
||||
to: {user.name, user.email},
|
||||
subject: "Account registered on #{instance_name}"
|
||||
)
|
||||
end
|
||||
|
||||
test "it requires an email, name, nickname and password, bio is optional when account_activation_required is enabled" do
|
||||
clear_config([:instance, :account_activation_required], true)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user