From 71fb75b7ef6bb847a381ce1b86bea9bef35a3a14 Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Jun 2019 22:29:36 +0300 Subject: [PATCH 1/2] User sign out mix task. --- lib/mix/tasks/pleroma/user.ex | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 7eaa49836..3a5382d0f 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -8,6 +8,7 @@ defmodule Mix.Tasks.Pleroma.User do alias Mix.Tasks.Pleroma.Common alias Pleroma.User alias Pleroma.UserInviteToken + alias Pleroma.Web.OAuth @shortdoc "Manages Pleroma users" @moduledoc """ @@ -49,6 +50,10 @@ defmodule Mix.Tasks.Pleroma.User do mix pleroma.user delete_activities NICKNAME + ## Sign user out from all applications (delete user's OAuth tokens and authorizations). + + mix pleroma.user sign_out NICKNAME + ## Deactivate or activate the user's account. mix pleroma.user toggle_activated NICKNAME @@ -407,6 +412,20 @@ def run(["toggle_confirmed", nickname]) do end end + def run(["sign_out", nickname]) do + Common.start_pleroma() + + with %User{} = user <- User.get_cached_by_nickname(nickname) do + OAuth.Token.delete_user_tokens(user) + OAuth.Authorization.delete_user_authorizations(user) + + Common.shell_info("#{nickname} signed out from all apps.") + else + _ -> + Common.shell_error("No local user #{nickname}") + end + end + defp set_moderator(user, value) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: value}) From 363618207c03188797be90b8c1cf7b3b293f557d Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Wed, 19 Jun 2019 19:39:53 +0000 Subject: [PATCH 2/2] Apply suggestion to lib/mix/tasks/pleroma/user.ex --- lib/mix/tasks/pleroma/user.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index 3a5382d0f..0efa745e4 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -415,7 +415,7 @@ def run(["toggle_confirmed", nickname]) do def run(["sign_out", nickname]) do Common.start_pleroma() - with %User{} = user <- User.get_cached_by_nickname(nickname) do + with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do OAuth.Token.delete_user_tokens(user) OAuth.Authorization.delete_user_authorizations(user)