Store new tokens.

This commit is contained in:
Martin Rotter 2017-09-27 14:43:52 +02:00
parent f0d9f31f50
commit a7359e3a95
4 changed files with 22 additions and 2 deletions

View File

@ -1522,7 +1522,8 @@ Assignment DatabaseQueries::getInoreaderFeeds(QSqlDatabase db, int account_id, b
return feeds; return feeds;
} }
bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token, const QString& refresh_token, int account_id) { bool DatabaseQueries::storeNewInoreaderTokens(QSqlDatabase db, const QString& access_token,
const QString& refresh_token, int account_id) {
QSqlQuery query(db); QSqlQuery query(db);
query.prepare("UPDATE InoreaderAccounts " query.prepare("UPDATE InoreaderAccounts "

View File

@ -38,6 +38,7 @@ InoreaderServiceRoot::InoreaderServiceRoot(InoreaderNetworkFactory* network, Roo
m_network->setParent(this); m_network->setParent(this);
} }
m_network->setService(this);
setIcon(InoreaderEntryPoint().icon()); setIcon(InoreaderEntryPoint().icon());
} }

View File

@ -22,6 +22,7 @@
#include "gui/dialogs/formmain.h" #include "gui/dialogs/formmain.h"
#include "gui/tabwidget.h" #include "gui/tabwidget.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/databasequeries.h"
#include "network-web/networkfactory.h" #include "network-web/networkfactory.h"
#include "network-web/oauth2service.h" #include "network-web/oauth2service.h"
#include "network-web/silentnetworkaccessmanager.h" #include "network-web/silentnetworkaccessmanager.h"
@ -29,6 +30,7 @@
#include "services/abstract/category.h" #include "services/abstract/category.h"
#include "services/inoreader/definitions.h" #include "services/inoreader/definitions.h"
#include "services/inoreader/inoreaderfeed.h" #include "services/inoreader/inoreaderfeed.h"
#include "services/inoreader/inoreaderserviceroot.h"
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@ -36,12 +38,16 @@
#include <QUrl> #include <QUrl>
InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent), InoreaderNetworkFactory::InoreaderNetworkFactory(QObject* parent) : QObject(parent),
m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE), m_service(nullptr), m_username(QString()), m_batchSize(INOREADER_DEFAULT_BATCH_SIZE),
m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL, m_oauth2(new OAuth2Service(INOREADER_OAUTH_AUTH_URL, INOREADER_OAUTH_TOKEN_URL,
INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) { INOREADER_OAUTH_CLI_ID, INOREADER_OAUTH_CLI_KEY, INOREADER_OAUTH_SCOPE)) {
initializeOauth(); initializeOauth();
} }
void InoreaderNetworkFactory::setService(InoreaderServiceRoot* service) {
m_service = service;
}
OAuth2Service* InoreaderNetworkFactory::oauth() const { OAuth2Service* InoreaderNetworkFactory::oauth() const {
return m_oauth2; return m_oauth2;
} }
@ -64,6 +70,14 @@ void InoreaderNetworkFactory::initializeOauth() {
qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical); qApp->showGuiMessage("Authentication error - Inoreader", error_description, QSystemTrayIcon::Critical);
}); });
connect(m_oauth2, &OAuth2Service::tokensReceived, [this](QString access_token, QString refresh_token, int expires_in) {
Q_UNUSED(expires_in)
if (m_service != nullptr && !access_token.isEmpty() && !refresh_token.isEmpty()) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className(), DatabaseFactory::FromSettings);
DatabaseQueries::storeNewInoreaderTokens(database, access_token, refresh_token, m_service->accountId());
}
});
} }
void InoreaderNetworkFactory::setUsername(const QString& username) { void InoreaderNetworkFactory::setUsername(const QString& username) {

View File

@ -26,6 +26,7 @@
#include <QNetworkReply> #include <QNetworkReply>
class RootItem; class RootItem;
class InoreaderServiceRoot;
class OAuth2Service; class OAuth2Service;
class InoreaderNetworkFactory : public QObject { class InoreaderNetworkFactory : public QObject {
@ -34,6 +35,8 @@ class InoreaderNetworkFactory : public QObject {
public: public:
explicit InoreaderNetworkFactory(QObject* parent = nullptr); explicit InoreaderNetworkFactory(QObject* parent = nullptr);
void setService(InoreaderServiceRoot* service);
OAuth2Service* oauth() const; OAuth2Service* oauth() const;
QString userName() const; QString userName() const;
@ -57,6 +60,7 @@ class InoreaderNetworkFactory : public QObject {
void initializeOauth(); void initializeOauth();
private: private:
InoreaderServiceRoot* m_service;
QString m_username; QString m_username;
int m_batchSize; int m_batchSize;
OAuth2Service* m_oauth2; OAuth2Service* m_oauth2;