better oauth workflow in acc edit dialog

This commit is contained in:
Martin Rotter 2017-09-26 10:57:27 +02:00
parent 6e5db70ee5
commit d07ae6f309
3 changed files with 17 additions and 18 deletions

View File

@ -21,6 +21,7 @@
#include "gui/guiutilities.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "network-web/oauth2service.h"
#include "services/inoreader/definitions.h"
#include "services/inoreader/inoreaderserviceroot.h"
@ -60,17 +61,10 @@ FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(pa
FormEditInoreaderAccount::~FormEditInoreaderAccount() {}
void FormEditInoreaderAccount::testSetup() {
if (m_network->isLoggedIn()) {
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
tr("Access granted successfully."),
tr("Access granted successfully."));
}
else {
m_network->login();
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Progress,
tr("Requested access approval. Respond to it, please."),
tr("Access approval was requested via OAuth 2.0 protocol."));
}
m_network->login();
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Progress,
tr("Requested access approval. Respond to it, please."),
tr("Access approval was requested via OAuth 2.0 protocol."));
}
void FormEditInoreaderAccount::onClickedOk() {
@ -108,14 +102,21 @@ void FormEditInoreaderAccount::checkUsername(const QString& username) {
}
void FormEditInoreaderAccount::hookNetwork() {
connect(m_network, &InoreaderNetworkFactory::accessGranted, [this]() {
connect(m_network->oauth(), &OAuth2Service::tokensReceived, [this]() {
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Ok,
tr("Tested successfully. You may be prompted to login once more."),
tr("Your access was approved."));
});
connect(m_network, &InoreaderNetworkFactory::error, [this](const QString& err) {
connect(m_network->oauth(), &OAuth2Service::tokensRetrieveError, [this](QString error, QString error_description) {
Q_UNUSED(error)
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("There is error. %1").arg(err),
tr("There is error. %1").arg(error_description),
tr("There was error during testing."));
});
connect(m_network->oauth(), &OAuth2Service::authFailed, [this]() {
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error,
tr("You did not grant access."),
tr("There was error during testing."));
});
}

View File

@ -67,6 +67,8 @@ void InoreaderNetworkFactory::login() {
void InoreaderNetworkFactory::initializeOauth() {
connect(m_oauth2, &OAuth2Service::tokensRetrieveError, [](QString error, QString error_description) {
Q_UNUSED(error)
qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical);
});
}

View File

@ -51,10 +51,6 @@ class InoreaderNetworkFactory : public QObject {
public slots:
void login();
signals:
void accessGranted();
void error(QString& description);
private:
void initializeOauth();