From: Olivier Goffart Date: Wed, 7 Jun 2017 14:19:34 +0000 (+0200) Subject: OAuth: Error handling in the wizard X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~710^2~22 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=04b6794318133b167acf3665023319bc95ff7f8b;p=nextcloud-desktop.git OAuth: Error handling in the wizard Issues: #5813 and #5811 --- diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 80b8b940a..7dc82bb7c 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -35,6 +35,7 @@ set(client_UI wizard/owncloudadvancedsetuppage.ui wizard/owncloudconnectionmethoddialog.ui wizard/owncloudhttpcredspage.ui + wizard/owncloudoauthcredspage.ui wizard/owncloudsetupnocredspage.ui wizard/owncloudwizardresultpage.ui ) diff --git a/src/gui/creds/oauth.h b/src/gui/creds/oauth.h index 93e7ac209..fe7fd1c40 100644 --- a/src/gui/creds/oauth.h +++ b/src/gui/creds/oauth.h @@ -50,6 +50,7 @@ public: enum Result { NotSupported, LoggedIn, Error }; + Q_ENUM(Result); void start(); bool openBrowser(); diff --git a/src/gui/wizard/owncloudoauthcredspage.cpp b/src/gui/wizard/owncloudoauthcredspage.cpp index 50f498a92..a4bf5988e 100644 --- a/src/gui/wizard/owncloudoauthcredspage.cpp +++ b/src/gui/wizard/owncloudoauthcredspage.cpp @@ -27,43 +27,62 @@ namespace OCC { OwncloudOAuthCredsPage::OwncloudOAuthCredsPage() : AbstractCredentialsWizardPage() - , _afterInitialSetup(false) - { + _ui.setupUi(this); + + Theme *theme = Theme::instance(); + _ui.topLabel->hide(); + _ui.bottomLabel->hide(); + QVariant variant = theme->customMedia(Theme::oCSetupTop); + WizardCommon::setupCustomMedia(variant, _ui.topLabel); + variant = theme->customMedia(Theme::oCSetupBottom); + WizardCommon::setupCustomMedia(variant, _ui.bottomLabel); + + WizardCommon::initErrorLabel(_ui.errorLabel); + + setTitle(WizardCommon::titleTemplate().arg(tr("Connect to %1").arg(Theme::instance()->appNameGUI()))); + setSubTitle(WizardCommon::subTitleTemplate().arg(tr("Login in your browser"))); + + connect(_ui.openLinkButton, &QCommandLinkButton::clicked, [this] { + _ui.errorLabel->hide(); + if (_asyncAuth) + _asyncAuth->openBrowser(); + }); } -void OwncloudOAuthCredsPage::setVisible(bool visible) +void OwncloudOAuthCredsPage::initializePage() { - if (!_afterInitialSetup) { - QWizardPage::setVisible(visible); - return; - } + OwncloudWizard *ocWizard = qobject_cast(wizard()); + Q_ASSERT(ocWizard); + ocWizard->account()->setCredentials(CredentialsFactory::create("http")); + _asyncAuth.reset(new OAuth(ocWizard->account().data(), this)); + connect(_asyncAuth.data(), &OAuth::result, this, &OwncloudOAuthCredsPage::asyncAuthResult, Qt::QueuedConnection); + _asyncAuth->start(); + wizard()->hide(); +} - if (isVisible() == visible) { - return; - } - if (visible) { - OwncloudWizard *ocWizard = qobject_cast(wizard()); - Q_ASSERT(ocWizard); - ocWizard->account()->setCredentials(CredentialsFactory::create("http")); - _asyncAuth.reset(new OAuth(ocWizard->account().data(), this)); - connect(_asyncAuth.data(), SIGNAL(result(OAuth::Result, QString, QString, QString)), - this, SLOT(asyncAuthResult(OAuth::Result, QString, QString, QString))); - _asyncAuth->start(); - wizard()->hide(); - } else { - // The next or back button was activated, show the wizard again - wizard()->show(); - } +void OCC::OwncloudOAuthCredsPage::cleanupPage() +{ + // The next or back button was activated, show the wizard again + wizard()->show(); + _asyncAuth.reset(); } void OwncloudOAuthCredsPage::asyncAuthResult(OAuth::Result r, const QString &user, const QString &token, const QString &refreshToken) { switch (r) { - case OAuth::NotSupported: + case OAuth::NotSupported: { + /* OAuth not supported (can't open browser), fallback to HTTP credentials */ + OwncloudWizard *ocWizard = qobject_cast(wizard()); + ocWizard->back(); + ocWizard->setAuthType(WizardCommon::HttpCreds); + break; + } case OAuth::Error: - qWarning() << "FIXME!!!"; + /* Error while getting the access token. (Timeout, or the server did not accept our client credentials */ + _ui.errorLabel->show(); + wizard()->show(); break; case OAuth::LoggedIn: { _token = token; @@ -77,11 +96,6 @@ void OwncloudOAuthCredsPage::asyncAuthResult(OAuth::Result r, const QString &use } } -void OwncloudOAuthCredsPage::initializePage() -{ - _afterInitialSetup = true; -} - int OwncloudOAuthCredsPage::nextId() const { return WizardCommon::Page_AdvancedSetup; @@ -100,4 +114,9 @@ AbstractCredentials *OwncloudOAuthCredsPage::getCredentials() const ocWizard->_clientSslCertificate, ocWizard->_clientSslKey); } +bool OwncloudOAuthCredsPage::isComplete() const +{ + return false; /* We can never go forward manually */ +} + } // namespace OCC diff --git a/src/gui/wizard/owncloudoauthcredspage.h b/src/gui/wizard/owncloudoauthcredspage.h index 2ef6365dd..f51a1896a 100644 --- a/src/gui/wizard/owncloudoauthcredspage.h +++ b/src/gui/wizard/owncloudoauthcredspage.h @@ -24,6 +24,9 @@ #include "accountfwd.h" #include "creds/oauth.h" +#include "ui_owncloudoauthcredspage.h" + + namespace OCC { @@ -36,25 +39,24 @@ public: AbstractCredentials *getCredentials() const Q_DECL_OVERRIDE; void initializePage() Q_DECL_OVERRIDE; + void cleanupPage() override; int nextId() const Q_DECL_OVERRIDE; void setConnected(); + bool isComplete() const override; public Q_SLOTS: - void setVisible(bool visible) Q_DECL_OVERRIDE; void asyncAuthResult(OAuth::Result, const QString &user, const QString &token, const QString &reniewToken); signals: void connectToOCUrl(const QString &); -private: - bool _afterInitialSetup; - public: QString _user; QString _token; QString _refreshToken; QScopedPointer _asyncAuth; + Ui_OwncloudOAuthCredsPage _ui; }; } // namespace OCC diff --git a/src/gui/wizard/owncloudoauthcredspage.ui b/src/gui/wizard/owncloudoauthcredspage.ui new file mode 100644 index 000000000..7b20b6cc4 --- /dev/null +++ b/src/gui/wizard/owncloudoauthcredspage.ui @@ -0,0 +1,87 @@ + + + OwncloudOAuthCredsPage + + + + 0 + 0 + 424 + 373 + + + + Form + + + + + + TextLabel + + + Qt::RichText + + + Qt::AlignCenter + + + true + + + + + + + Please switch to your browser to proceed. + + + true + + + + + + + An error occured while connecting. Please try again. + + + Qt::PlainText + + + + + + + Re-open Browser + + + + + + + Qt::Vertical + + + + 20 + 127 + + + + + + + + TextLabel + + + Qt::RichText + + + + + + + +