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

View file

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

View file

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