[#114] Allowed unconfirmed users to authenticate if :account_activation_required is disabled prior to confirmation.

Ensured that no confirmation emails are sent if :account_activation_required is not true. Adjusted tests.
This commit is contained in:
Ivan Tashkinov 2018-12-20 14:48:48 +03:00
parent f69cbf4755
commit 7cab7de9ff
2 changed files with 13 additions and 2 deletions

View File

@ -38,7 +38,10 @@ defmodule Pleroma.User do
timestamps() timestamps()
end end
def auth_active?(%User{} = user), do: user.info && !user.info.confirmation_pending def auth_active?(%User{} = user) do
(user.info && !user.info.confirmation_pending) ||
!Pleroma.Config.get([:instance, :account_activation_required])
end
def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info) def superuser?(%User{} = user), do: user.info && User.Info.superuser?(user.info)
@ -220,7 +223,8 @@ def register(%Ecto.Changeset{} = changeset) do
end end
def try_send_confirmation_email(%User{} = user) do def try_send_confirmation_email(%User{} = user) do
if user.info.confirmation_pending do if user.info.confirmation_pending &&
Pleroma.Config.get([:instance, :account_activation_required]) do
user user
|> Pleroma.UserEmail.account_confirmation_email() |> Pleroma.UserEmail.account_confirmation_email()
|> Pleroma.Mailer.deliver() |> Pleroma.Mailer.deliver()

View File

@ -919,6 +919,13 @@ test "it returns 500 if token is invalid", %{conn: conn, user: user} do
describe "POST /api/account/resend_confirmation_email" do describe "POST /api/account/resend_confirmation_email" do
setup do setup do
setting = Pleroma.Config.get([:instance, :account_activation_required])
unless setting do
Pleroma.Config.put([:instance, :account_activation_required], true)
on_exit(fn -> Pleroma.Config.put([:instance, :account_activation_required], setting) end)
end
user = insert(:user) user = insert(:user)
info_change = User.Info.confirmation_changeset(user.info, :unconfirmed) info_change = User.Info.confirmation_changeset(user.info, :unconfirmed)