diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 07ab0970f6..8a5c11b907 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -78,7 +78,12 @@ AccountPtr Account::sharedFromThis() QString Account::user() const { - return _credentials->user(); + return _user.isEmpty() ? _credentials->user() : _user; +} + +void Account::setUser(const QString &user) +{ + _user = user; } QString Account::displayName() const diff --git a/src/libsync/account.h b/src/libsync/account.h index 797cd14227..62098b218a 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -77,6 +77,7 @@ public: /// The user that can be used in dav url QString user() const; + void setUser(const QString &user); /// The name of the account as shown in the toolbar QString displayName() const; @@ -209,6 +210,7 @@ private: QWeakPointer _sharedThis; QString _id; + QString _user; QMap _settingsMap; QUrl _url; QList _approvedCerts; diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp index 2a955a5214..814f4a303c 100644 --- a/src/libsync/connectionvalidator.cpp +++ b/src/libsync/connectionvalidator.cpp @@ -229,10 +229,26 @@ void ConnectionValidator::slotCapabilitiesRecieved(const QVariantMap &json) auto caps = json.value("ocs").toMap().value("data").toMap().value("capabilities"); qDebug() << "Server capabilities" << caps; _account->setCapabilities(caps.toMap()); - reportResult(Connected); - return; + fetchUser(); } +void ConnectionValidator::fetchUser() +{ + + JsonApiJob *job = new JsonApiJob(_account, QLatin1String("ocs/v1.php/cloud/user"), this); + job->setTimeout(timeoutToUseMsec); + QObject::connect(job, SIGNAL(jsonReceived(QVariantMap, int)), this, SLOT(slotUserFetched(QVariantMap))); + job->start(); +} + +void ConnectionValidator::slotUserFetched(const QVariantMap &json) +{ + QString user = json.value("ocs").toMap().value("data").toMap().value("id").toString(); + if (!user.isEmpty()) { + _account->setUser(user); + } + reportResult(Connected); +} void ConnectionValidator::reportResult(Status status) { diff --git a/src/libsync/connectionvalidator.h b/src/libsync/connectionvalidator.h index e1264628ac..b97d665ec8 100644 --- a/src/libsync/connectionvalidator.h +++ b/src/libsync/connectionvalidator.h @@ -27,7 +27,7 @@ namespace OCC { * This is a job-like class to check that the server is up and that we are connected. * There are two entry points: checkServerAndAuth and checkAuthentication * checkAuthentication is the quick version that only does the propfind - * while checkServerAndAuth is doing the 3 calls. + * while checkServerAndAuth is doing the 4 calls. * * We cannot use the capabilites call to test the login and the password because of * https://github.com/owncloud/core/issues/12930 @@ -60,7 +60,15 @@ namespace OCC { +-> checkServerCapabilities (cloud/capabilities) JsonApiJob | - +-> slotCapabilitiesRecieved --> X + +-> slotCapabilitiesRecieved -+ + | + +-----------------------------------+ + | + +-> fetchUser + PropfindJob + | + +-> slotUserFetched --> X + \endcode */ class OWNCLOUDSYNC_EXPORT ConnectionValidator : public QObject @@ -109,10 +117,12 @@ protected slots: void slotAuthSuccess(); void slotCapabilitiesRecieved(const QVariantMap&); + void slotUserFetched(const QVariantMap &); private: void reportResult(Status status); void checkServerCapabilities(); + void fetchUser(); QStringList _errors; AccountPtr _account;