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));
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()