From f9daa27a5dccdca07e8bf80733394bbd167431f3 Mon Sep 17 00:00:00 2001 From: Felix Weilbach Date: Wed, 11 Aug 2021 15:18:22 +0200 Subject: [PATCH] Enforce fetching of user id With the change of commit 3e61bdc4318827d486221e56fbca3804b639fdd7 and the relase of v3.3.0 users that had their email address used as login are not able to login anymore. The dav_user should be empty if users tried to create a account in the meantime. Therefore we fetch the user id in the case dav_user (and then Account::_davUser) is empty. We then store the user id in dav_user. Signed-off-by: Felix Weilbach --- src/gui/accountmanager.cpp | 2 +- src/libsync/account.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 150fa45451..cfa569b6a6 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -317,7 +317,7 @@ AccountPtr AccountManager::loadAccountHelper(QSettings &settings) qCInfo(lcAccountManager) << "Account for" << acc->url() << "using auth type" << authType; acc->_serverVersion = settings.value(QLatin1String(serverVersionC)).toString(); - acc->_davUser = settings.value(QLatin1String(davUserC)).toString(); + acc->_davUser = settings.value(QLatin1String(davUserC), "").toString(); // We want to only restore settings for that auth type and the user value acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC)); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 5b3289f1d6..52a8c1c4d5 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -488,7 +488,27 @@ void Account::slotHandleSslErrors(QNetworkReply *reply, QList errors) void Account::slotCredentialsFetched() { - emit credentialsFetched(_credentials.data()); + if (_davUser.isEmpty()) { + qCDebug(lcAccount) << "User id not set. Fetch it."; + const auto fetchUserNameJob = new JsonApiJob(sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user")); + connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, fetchUserNameJob](const QJsonDocument &json, int statusCode) { + fetchUserNameJob->deleteLater(); + if (statusCode != 100) { + qCWarning(lcAccount) << "Could not fetch user id. Login will probably not work."; + emit credentialsFetched(_credentials.data()); + return; + } + + const auto objData = json.object().value("ocs").toObject().value("data").toObject(); + const auto userId = objData.value("id").toString(""); + setDavUser(userId); + emit credentialsFetched(_credentials.data()); + }); + fetchUserNameJob->start(); + } else { + qCDebug(lcAccount) << "User id already fetched."; + emit credentialsFetched(_credentials.data()); + } } void Account::slotCredentialsAsked()