UserEnabledPlug: Don't authenticate unconfirmed users.
authorlain <lain@soykaf.club>
Mon, 11 Nov 2019 11:43:46 +0000 (12:43 +0100)
committerlain <lain@soykaf.club>
Mon, 11 Nov 2019 11:43:46 +0000 (12:43 +0100)
lib/pleroma/plugs/user_enabled_plug.ex
test/plugs/user_enabled_plug_test.exs

index fbb4bf11575e41178bf0dcdfe55c05511f682567..8d102ee5b8d47207aa1e527c79f47866326f9b90 100644 (file)
@@ -10,9 +10,13 @@ defmodule Pleroma.Plugs.UserEnabledPlug do
     options
   end
 
-  def call(%{assigns: %{user: %User{deactivated: true}}} = conn, _) do
-    conn
-    |> assign(:user, nil)
+  def call(%{assigns: %{user: %User{} = user}} = conn, _) do
+    if User.auth_active?(user) do
+      conn
+    else
+      conn
+      |> assign(:user, nil)
+    end
   end
 
   def call(conn, _) do
index 996a7d77b11223078eefe67e564feaea4d4e399d..a4035bf0e0c9fd3137c8e760d054085163d90c74 100644 (file)
@@ -16,6 +16,23 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do
     assert ret_conn == conn
   end
 
+  test "with a user that's not confirmed and a config requiring confirmation, it removes that user",
+       %{conn: conn} do
+    old = Pleroma.Config.get([:instance, :account_activation_required])
+    Pleroma.Config.put([:instance, :account_activation_required], true)
+
+    user = insert(:user, confirmation_pending: true)
+
+    conn =
+      conn
+      |> assign(:user, user)
+      |> UserEnabledPlug.call(%{})
+
+    assert conn.assigns.user == nil
+
+    Pleroma.Config.put([:instance, :account_activation_required], old)
+  end
+
   test "with a user that is deactivated, it removes that user", %{conn: conn} do
     user = insert(:user, deactivated: true)