#include "accountmanager.h"
#include "owncloudsetupwizard.h"
#include "creds/abstractcredentials.h"
+#include "creds/httpcredentialsgui.h"
#include "tooltipupdater.h"
#include "filesystem.h"
ui->connectLabel->setText(tr("No account configured."));
- connect(_accountState, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
- slotAccountStateChanged(_accountState->state());
+ connect(_accountState, &AccountState::stateChanged, this, &AccountSettings::slotAccountStateChanged);
+ slotAccountStateChanged();
connect(&_quotaInfo, SIGNAL(quotaUpdated(qint64, qint64)),
this, SLOT(slotUpdateQuota(qint64, qint64)));
}
}
-void AccountSettings::slotAccountStateChanged(int state)
+void AccountSettings::slotAccountStateChanged()
{
+ int state = _accountState ? _accountState->state() : AccountState::Disconnected;
if (_accountState) {
ui->sslButton->updateAccountState(_accountState);
AccountPtr account = _accountState->account();
showConnectionLabel(tr("Server %1 is currently in maintenance mode.").arg(server));
} else if (state == AccountState::SignedOut) {
showConnectionLabel(tr("Signed out from %1.").arg(serverWithUser));
+ } else if (state == AccountState::AskingCredentials) {
+ QUrl url;
+ if (auto cred = qobject_cast<HttpCredentialsGui *>(account->credentials())) {
+ connect(cred, &HttpCredentialsGui::authorisationLinkChanged,
+ this, &AccountSettings::slotAccountStateChanged, Qt::UniqueConnection);
+ url = cred->authorisationLink();
+ }
+ if (url.isValid()) {
+ showConnectionLabel(tr("Obtaining authorization from the browser. "
+ "<a href='%1'>Click here</a> to re-open the browser.")
+ .arg(url.toString(QUrl::FullyEncoded)));
+ } else {
+ showConnectionLabel(tr("Connecting to %1...").arg(serverWithUser));
+ }
} else {
showConnectionLabel(tr("No connection to %1 at %2.")
.arg(Utility::escape(Theme::instance()->appNameGUI()), server),
public slots:
void slotOpenOC();
void slotUpdateQuota(qint64, qint64);
- void slotAccountStateChanged(int state);
+ void slotAccountStateChanged();
AccountState *accountsState() { return _accountState; }
return tr("Network error");
case ConfigurationError:
return tr("Configuration error");
+ case AskingCredentials:
+ return tr("Asking Credentials");
}
return tr("Unknown account state");
}
account()->credentials()->invalidateToken();
account()->credentials()->askFromUser();
- setState(ConfigurationError);
+ setState(AskingCredentials);
_waitingForNewCredentials = true;
}
/// again automatically.
NetworkError,
- /// An error like invalid credentials where retrying won't help.
- ConfigurationError
+ /// Server configuration error. (For example: unsupported version)
+ ConfigurationError,
+
+ /// We are currently asking the user for credentials
+ AskingCredentials
};
/// The actual current connectivity status.
// Don't check if we're manually signed out or
// when the error is permanent.
if (state != AccountState::SignedOut
- && state != AccountState::ConfigurationError) {
+ && state != AccountState::ConfigurationError
+ && state != AccountState::AskingCredentials) {
accountState->checkConnectivity();
}
}
_asyncAuth.reset(new OAuth(_account, this));
connect(_asyncAuth.data(), &OAuth::result,
this, &HttpCredentialsGui::asyncAuthResult);
+ connect(_asyncAuth.data(), &OAuth::destroyed,
+ this, &HttpCredentialsGui::authorisationLinkChanged);
_asyncAuth->start();
+ emit authorisationLinkChanged();
} else if (reply->error() == QNetworkReply::AuthenticationRequiredError) {
// Show the dialog
// We will re-enter the event loop, so better wait the next iteration
* or call showDialog to ask the password
*/
Q_INVOKABLE void askFromUser() Q_DECL_OVERRIDE;
+ /**
+ * In case of oauth, return an URL to the link to open the browser.
+ * An invalid URL otherwise
+ */
+ QUrl authorisationLink() const { return _asyncAuth ? _asyncAuth->authorisationLink() : QUrl(); }
+
static QString requestAppPasswordText(const Account *account);
private slots:
void asyncAuthResult(OAuth::Result, const QString &user, const QString &accessToken, const QString &refreshToken);
void showDialog();
+signals:
+ void authorisationLinkChanged();
+
private:
QScopedPointer<OAuth, QScopedPointerObjectDeleteLater<OAuth>> _asyncAuth;
};
QTimer::singleShot(5 * 60 * 1000, this, [this] { result(Error); });
}
-
-bool OAuth::openBrowser()
+QUrl OAuth::authorisationLink() const
{
Q_ASSERT(_server.isListening());
- auto url = QUrl(_account->url().toString()
+ return QUrl(_account->url().toString()
+ QLatin1String("/index.php/apps/oauth2/authorize?response_type=code&client_id=")
+ Theme::instance()->oauthClientId()
+ QLatin1String("&redirect_uri=http://localhost:") + QString::number(_server.serverPort()));
+}
-
- if (!QDesktopServices::openUrl(url)) {
+bool OAuth::openBrowser()
+{
+ if (!QDesktopServices::openUrl(authorisationLink())) {
// We cannot open the browser, then we claim we don't support OAuth.
emit result(NotSupported, QString());
return false;
#pragma once
#include <QPointer>
#include <QTcpServer>
+#include <QUrl>
namespace OCC {
Q_ENUM(Result);
void start();
bool openBrowser();
+ QUrl authorisationLink() const;
signals:
/**