From c930d8e30f4527d173bec3567a78c6ef2084015e Mon Sep 17 00:00:00 2001 From: allexzander Date: Wed, 28 Jul 2021 16:52:56 +0300 Subject: [PATCH] Delete apptoken after account removal. Signed-off-by: allexzander --- src/gui/accountmanager.cpp | 2 ++ src/libsync/account.cpp | 24 +++++++++++++++++++++++- src/libsync/account.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 165be3c97..150fa4545 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -380,6 +380,8 @@ void AccountManager::deleteAccount(AccountState *account) // Forget E2E keys account->account()->e2e()->forgetSensitiveData(account->account()); + account->account()->deleteAppToken(); + emit accountSyncConnectionRemoved(account); emit accountRemoved(account); } diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 13e516400..5b3289f1d 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -23,6 +23,8 @@ #include "pushnotifications.h" #include "version.h" +#include + #include "common/asserts.h" #include "clientsideencryption.h" @@ -618,7 +620,8 @@ void Account::retrieveAppPassword(){ job->start(); } -void Account::deleteAppPassword(){ +void Account::deleteAppPassword() +{ const QString kck = AbstractCredentials::keychainKey( url().toString(), credentials()->user() + app_password, @@ -646,6 +649,25 @@ void Account::deleteAppPassword(){ job->start(); } +void Account::deleteAppToken() +{ + const auto deleteAppTokenJob = new DeleteJob(sharedFromThis(), QStringLiteral("/ocs/v2.php/core/apppassword")); + connect(deleteAppTokenJob, &DeleteJob::finishedSignal, this, [this]() { + if (const auto deleteJob = qobject_cast(QObject::sender())) { + const auto httpCode = deleteJob->reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (httpCode != 200) { + qCWarning(lcAccount) << "AppToken remove failed for user: " << displayName() << " with code: " << httpCode; + } else { + qCInfo(lcAccount) << "AppToken for user: " << displayName() << " has been removed."; + } + } else { + Q_ASSERT(false); + qCWarning(lcAccount) << "The sender is not a DeleteJob instance."; + } + }); + deleteAppTokenJob->start(); +} + void Account::fetchDirectEditors(const QUrl &directEditingURL, const QString &directEditingETag) { if(directEditingURL.isEmpty() || directEditingETag.isEmpty()) diff --git a/src/libsync/account.h b/src/libsync/account.h index a95df40dd..1b4e2d2e4 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -245,6 +245,8 @@ public: void writeAppPasswordOnce(QString appPassword); void deleteAppPassword(); + void deleteAppToken(); + /// Direct Editing // Check for the directEditing capability void fetchDirectEditors(const QUrl &directEditingURL, const QString &directEditingETag); -- 2.30.2