Merge branch 'bugfix/1395-email-activation' into 'develop'
Bugfix/1395 email activation Closes #1395 See merge request pleroma/pleroma!1965
This commit is contained in:
commit
22554ac5ca
|
@ -71,7 +71,7 @@ defp fetch_user_and_token(token) do
|
||||||
)
|
)
|
||||||
|
|
||||||
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
# credo:disable-for-next-line Credo.Check.Readability.MaxLineLength
|
||||||
with %Token{user: %{deactivated: false} = user} = token_record <- Repo.one(query) do
|
with %Token{user: user} = token_record <- Repo.one(query) do
|
||||||
{:ok, user, token_record}
|
{:ok, user, token_record}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,14 @@ def init(options) do
|
||||||
options
|
options
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(%{assigns: %{user: %User{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
|
||||||
|
|
|
@ -124,6 +124,9 @@ defmodule Pleroma.User do
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@doc "Returns if the user should be allowed to authenticate"
|
||||||
|
def auth_active?(%User{deactivated: true}), do: false
|
||||||
|
|
||||||
def auth_active?(%User{confirmation_pending: true}),
|
def auth_active?(%User{confirmation_pending: true}),
|
||||||
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
do: !Pleroma.Config.get([:instance, :account_activation_required])
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ defmodule Pleroma.Web.Router do
|
||||||
pipeline :oauth do
|
pipeline :oauth do
|
||||||
plug(:fetch_session)
|
plug(:fetch_session)
|
||||||
plug(Pleroma.Plugs.OAuthPlug)
|
plug(Pleroma.Plugs.OAuthPlug)
|
||||||
|
plug(Pleroma.Plugs.UserEnabledPlug)
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api do
|
pipeline :api do
|
||||||
|
|
|
@ -16,6 +16,23 @@ test "doesn't do anything if the user isn't set", %{conn: conn} 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, deactivated: true)
|
user = insert(:user, deactivated: true)
|
||||||
|
|
||||||
|
|
|
@ -1195,6 +1195,13 @@ test "auth_active?/1 works correctly" do
|
||||||
refute User.auth_active?(local_user)
|
refute User.auth_active?(local_user)
|
||||||
assert User.auth_active?(confirmed_user)
|
assert User.auth_active?(confirmed_user)
|
||||||
assert User.auth_active?(remote_user)
|
assert User.auth_active?(remote_user)
|
||||||
|
|
||||||
|
# also shows unactive for deactivated users
|
||||||
|
|
||||||
|
deactivated_but_confirmed =
|
||||||
|
insert(:user, local: true, confirmation_pending: false, deactivated: true)
|
||||||
|
|
||||||
|
refute User.auth_active?(deactivated_but_confirmed)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "superuser?/1" do
|
describe "superuser?/1" do
|
||||||
|
|
Loading…
Reference in New Issue