diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index 150fa4545..cfa569b6a 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 5b3289f1d..52a8c1c4d 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()