UserEnabledPlug: Don't authenticate unconfirmed users.
This commit is contained in:
parent
ff4af8c5ee
commit
5b5f855237
@ -10,10 +10,14 @@ defmodule Pleroma.Plugs.UserEnabledPlug do
|
|||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(%{assigns: %{user: %User{info: %{deactivated: true}}}} = conn, _) do
|
def call(%{assigns: %{user: %User{} = user}} = conn, _) do
|
||||||
|
if User.auth_active?(user) do
|
||||||
|
conn
|
||||||
|
else
|
||||||
conn
|
conn
|
||||||
|> assign(:user, nil)
|
|> assign(:user, nil)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def call(conn, _) do
|
def call(conn, _) do
|
||||||
conn
|
conn
|
||||||
|
@ -16,6 +16,23 @@ defmodule Pleroma.Plugs.UserEnabledPlugTest do
|
|||||||
assert ret_conn == conn
|
assert ret_conn == conn
|
||||||
end
|
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
|
test "with a user that is deactivated, it removes that user", %{conn: conn} do
|
||||||
user = insert(:user, info: %{deactivated: true})
|
user = insert(:user, info: %{deactivated: true})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user