Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorFabian Müller <fmueller@owncloud.com>2022-05-24 11:14:29 +0300
committerHannah von Reth <vonreth@kde.org>2022-05-24 15:39:02 +0300
commit3afb7a5ebdb64dcd3da1c0b5b110dc6a6c50aa6d (patch)
tree2cdd8dd90e80c8542ad955beea2e4534274e20bf /src/gui
parent43df0da5841a0f8181f51426ce8b321cf6092cfb (diff)
Use user's display name in local sync directory name
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/newwizard/setupwizardaccountbuilder.cpp11
-rw-r--r--src/gui/newwizard/setupwizardaccountbuilder.h3
-rw-r--r--src/gui/newwizard/setupwizardcontroller.cpp27
-rw-r--r--src/gui/newwizard/setupwizardcontroller.h2
4 files changed, 35 insertions, 8 deletions
diff --git a/src/gui/newwizard/setupwizardaccountbuilder.cpp b/src/gui/newwizard/setupwizardaccountbuilder.cpp
index 25ebfc682..7a5dce824 100644
--- a/src/gui/newwizard/setupwizardaccountbuilder.cpp
+++ b/src/gui/newwizard/setupwizardaccountbuilder.cpp
@@ -109,6 +109,8 @@ AccountPtr SetupWizardAccountBuilder::build()
newAccountPtr->setDavUser(_authenticationStrategy->davUser());
newAccountPtr->setCredentials(_authenticationStrategy->makeCreds());
+ newAccountPtr->setDavDisplayName(_displayName);
+
newAccountPtr->addApprovedCerts({ _customTrustedCaCertificates.begin(), _customTrustedCaCertificates.end() });
return newAccountPtr;
@@ -125,9 +127,12 @@ bool SetupWizardAccountBuilder::hasValidCredentials() const
QString SetupWizardAccountBuilder::displayName() const
{
- Q_ASSERT(hasValidCredentials());
- // TODO: get the correct display name instead of the dav user
- return _authenticationStrategy->davUser();
+ return _displayName;
+}
+
+void SetupWizardAccountBuilder::setDisplayName(const QString &displayName)
+{
+ _displayName = displayName;
}
void SetupWizardAccountBuilder::setAuthenticationStrategy(AbstractAuthenticationStrategy *strategy)
diff --git a/src/gui/newwizard/setupwizardaccountbuilder.h b/src/gui/newwizard/setupwizardaccountbuilder.h
index c43e714fe..06f4b3a51 100644
--- a/src/gui/newwizard/setupwizardaccountbuilder.h
+++ b/src/gui/newwizard/setupwizardaccountbuilder.h
@@ -117,6 +117,7 @@ public:
bool hasValidCredentials() const;
QString displayName() const;
+ void setDisplayName(const QString &displayName);
/**
* Store custom CA certificate for the newly built account.
@@ -138,6 +139,8 @@ public:
private:
QUrl _serverUrl;
+ QString _displayName;
+
DetermineAuthTypeJob::AuthType _authType = DetermineAuthTypeJob::AuthType::Unknown;
std::unique_ptr<AbstractAuthenticationStrategy> _authenticationStrategy;
diff --git a/src/gui/newwizard/setupwizardcontroller.cpp b/src/gui/newwizard/setupwizardcontroller.cpp
index 5705c2a8e..e3c87934b 100644
--- a/src/gui/newwizard/setupwizardcontroller.cpp
+++ b/src/gui/newwizard/setupwizardcontroller.cpp
@@ -7,6 +7,7 @@
#include "gui/folderman.h"
#include "jobs/checkbasicauthjobfactory.h"
#include "jobs/resolveurljobfactory.h"
+#include "networkjobs/fetchuserinfojobfactory.h"
#include "pages/accountconfiguredwizardpage.h"
#include "pages/basiccredentialssetupwizardpage.h"
#include "pages/oauthcredentialssetupwizardpage.h"
@@ -233,7 +234,7 @@ void SetupWizardController::nextStep(std::optional<PageIndex> currentPage, std::
// username might not be set yet, shouldn't matter, though
auto oAuth = new OAuth(_accountBuilder.serverUrl(), QString(), _accessManager, {}, this);
- connect(oAuth, &OAuth::result, this, [this, newPage](OAuth::Result result, const QString &user, const QString &token, const QString &refreshToken) {
+ connect(oAuth, &OAuth::result, this, [this, newPage](OAuth::Result result, const QString &userName, const QString &token, const QString &displayName, const QString &refreshToken) {
// the button may not be clicked any more, since the server has been shut down right before this signal was emitted by the OAuth instance
newPage->disableButtons();
@@ -244,7 +245,8 @@ void SetupWizardController::nextStep(std::optional<PageIndex> currentPage, std::
switch (result) {
case OAuth::Result::LoggedIn: {
- _accountBuilder.setAuthenticationStrategy(new OAuth2AuthenticationStrategy(user, token, refreshToken));
+ _accountBuilder.setAuthenticationStrategy(new OAuth2AuthenticationStrategy(userName, token, refreshToken));
+ _accountBuilder.setDisplayName(displayName);
nextStep(1, std::nullopt);
break;
}
@@ -355,13 +357,30 @@ void SetupWizardController::nextStep(std::optional<PageIndex> currentPage, std::
_wizardWindow->displayPage(_currentPage, 1);
};
- connect(checkBasicAuthJob, &CoreJob::finished, this, [moveToFinalPage, checkBasicAuthJob, showCredentialsPageAgain]() {
+ connect(checkBasicAuthJob, &CoreJob::finished, this, [moveToFinalPage, checkBasicAuthJob, showCredentialsPageAgain, this, strategy]() {
if (checkBasicAuthJob->success()) {
if (checkBasicAuthJob->result().toBool()) {
- moveToFinalPage();
+ auto fetchUserInfoJob = FetchUserInfoJobFactory::fromBasicAuthCredentials(_accessManager, strategy->username(), strategy->password(), this).startJob(_accountBuilder.serverUrl());
+
+ connect(fetchUserInfoJob, &CoreJob::finished, this, [this, strategy, moveToFinalPage, showCredentialsPageAgain, fetchUserInfoJob] {
+ if (fetchUserInfoJob->success()) {
+ auto result = fetchUserInfoJob->result().value<FetchUserInfoResult>();
+
+ Q_ASSERT(result.userName() == strategy->username());
+
+ _accountBuilder.setDisplayName(result.displayName());
+
+ moveToFinalPage();
+ } else {
+ showCredentialsPageAgain(tr("Failed to fetch user display name"));
+ }
+ });
+
} else {
showCredentialsPageAgain(tr("Login failed: username and/or password incorrect"));
}
+
+
} else {
showCredentialsPageAgain(tr("Login failed: %1").arg(checkBasicAuthJob->errorMessage()));
}
diff --git a/src/gui/newwizard/setupwizardcontroller.h b/src/gui/newwizard/setupwizardcontroller.h
index 335ade097..f7783742f 100644
--- a/src/gui/newwizard/setupwizardcontroller.h
+++ b/src/gui/newwizard/setupwizardcontroller.h
@@ -50,7 +50,7 @@ Q_SIGNALS:
void finished(AccountPtr newAccount, SyncMode syncMode);
private:
- void nextStep(std::optional<PageIndex> currentPage, std::optional<PageIndex> desiredPage);
+ void nextStep(std::optional<PageIndex> currentPage, std::optional<PageIndex> userName);
SetupWizardWindow *_wizardWindow;