diff --git a/src/gui/wizard/flow2authwidget.cpp b/src/gui/wizard/flow2authwidget.cpp index edb0812cb..901c2e991 100644 --- a/src/gui/wizard/flow2authwidget.cpp +++ b/src/gui/wizard/flow2authwidget.cpp @@ -16,12 +16,18 @@ #include "common/utility.h" #include "account.h" +#include "creds/webflowcredentials.h" +#include "networkjobs.h" #include "wizard/owncloudwizardcommon.h" #include "theme.h" #include "linklabel.h" #include "QProgressIndicator.h" +#include +#include +#include + namespace OCC { Q_LOGGING_CATEGORY(lcFlow2AuthWidget, "nextcloud.gui.wizard.flow2authwidget", QtInfoMsg) @@ -102,7 +108,25 @@ void Flow2AuthWidget::slotAuthResult(Flow2Auth::Result r, const QString &errorSt } } - emit authResult(r, errorString, user, appPassword); + _account->setCredentials(new WebFlowCredentials(user, appPassword)); + const auto fetchUserNameJob = new JsonApiJob(_account->sharedFromThis(), QStringLiteral("/ocs/v1.php/cloud/user")); + connect(fetchUserNameJob, &JsonApiJob::jsonReceived, this, [this, fetchUserNameJob, r, errorString, user, appPassword](const QJsonDocument &json, int statusCode) { + fetchUserNameJob->deleteLater(); + if (statusCode != 100) { + qCWarning(lcFlow2AuthWidget) << "Could not fetch username"; + _account->setDavDisplayName(user); + emit authResult(r, errorString, user, appPassword); + return; + } + + const auto objData = json.object().value("ocs").toObject().value("data").toObject(); + const auto userId = objData.value("id").toString(user); + const auto displayName = objData.value("display-name").toString(); + _account->setDavDisplayName(displayName); + + emit authResult(r, errorString, userId, appPassword); + }); + fetchUserNameJob->start(); } void Flow2AuthWidget::setError(const QString &error) { diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp index 51ea0eb9c..9a7dff87f 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.cpp +++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp @@ -168,7 +168,7 @@ void OwncloudAdvancedSetupPage::initializePage() _ui.confCheckBoxExternal->setChecked(cfgFile.confirmExternalStorage()); fetchUserAvatar(); - fetchUserData(); + setUserInformation(); customizeStyle(); @@ -201,20 +201,9 @@ void OwncloudAdvancedSetupPage::fetchUserAvatar() avatarJob->start(); } -void OwncloudAdvancedSetupPage::fetchUserData() +void OwncloudAdvancedSetupPage::setUserInformation() { const auto account = _ocWizard->account(); - - // Fetch user data - const auto userJob = new JsonApiJob(account, QLatin1String("ocs/v1.php/cloud/user"), this); - userJob->setTimeout(20 * 1000); - connect(userJob, &JsonApiJob::jsonReceived, this, [this](const QJsonDocument &json) { - const auto objData = json.object().value("ocs").toObject().value("data").toObject(); - const auto displayName = objData.value("display-name").toString(); - _ui.userNameLabel->setText(displayName); - }); - userJob->start(); - const auto serverUrl = account->url().toString(); setServerAddressLabelUrl(serverUrl); const auto userName = account->davDisplayName(); diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h index cb1fa064c..f3bf968d8 100644 --- a/src/gui/wizard/owncloudadvancedsetuppage.h +++ b/src/gui/wizard/owncloudadvancedsetuppage.h @@ -82,7 +82,7 @@ private: void setResolutionGuiVisible(bool value); void setupResoultionWidget(); void fetchUserAvatar(); - void fetchUserData(); + void setUserInformation(); // TODO: remove when UX decision is made void refreshVirtualFilesAvailibility(const QString &path);