瀏覽代碼

Delete apptoken after account removal.

Signed-off-by: allexzander <blackslayer4@gmail.com>
allexzander 4 年之前
父節點
當前提交
c930d8e30f
共有 3 個文件被更改,包括 27 次插入1 次删除
  1. 2 0
      src/gui/accountmanager.cpp
  2. 23 1
      src/libsync/account.cpp
  3. 2 0
      src/libsync/account.h

+ 2 - 0
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);
 }

+ 23 - 1
src/libsync/account.cpp

@@ -23,6 +23,8 @@
 #include "pushnotifications.h"
 #include "version.h"
 
+#include <deletejob.h>
+
 #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<DeleteJob *>(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())

+ 2 - 0
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);