save
This commit is contained in:
parent
ca364b9688
commit
c6c84daaed
@ -10,6 +10,8 @@
|
|||||||
#include "network-web/oauth2service.h"
|
#include "network-web/oauth2service.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/feedly/definitions.h"
|
#include "services/feedly/definitions.h"
|
||||||
|
#include "services/feedly/feedlynetwork.h"
|
||||||
|
#include "services/feedly/feedlyserviceroot.h"
|
||||||
#include "services/gmail/definitions.h"
|
#include "services/gmail/definitions.h"
|
||||||
#include "services/gmail/gmailfeed.h"
|
#include "services/gmail/gmailfeed.h"
|
||||||
#include "services/gmail/gmailserviceroot.h"
|
#include "services/gmail/gmailserviceroot.h"
|
||||||
@ -1848,7 +1850,7 @@ bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString&
|
|||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
|
q.prepare("INSERT INTO FeedlyAccounts (id, username, developer_access_token, refresh_token, msg_limit) "
|
||||||
"VALUES (:id, :service, :username, :developer_access_token, :refresh_token, :msg_limit);");
|
"VALUES (:id, :username, :developer_access_token, :refresh_token, :msg_limit);");
|
||||||
q.bindValue(QSL(":id"), id_to_assign);
|
q.bindValue(QSL(":id"), id_to_assign);
|
||||||
q.bindValue(QSL(":username"), username);
|
q.bindValue(QSL(":username"), username);
|
||||||
q.bindValue(QSL(":developer_access_token"), developer_access_token);
|
q.bindValue(QSL(":developer_access_token"), developer_access_token);
|
||||||
@ -2590,6 +2592,45 @@ QStringList DatabaseQueries::getAllRecipients(const QSqlDatabase& db, int accoun
|
|||||||
return rec;
|
return rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<ServiceRoot*> DatabaseQueries::getFeedlyAccounts(const QSqlDatabase& db, bool* ok) {
|
||||||
|
QSqlQuery query(db);
|
||||||
|
QList<ServiceRoot*> roots;
|
||||||
|
|
||||||
|
if (query.exec("SELECT * FROM FeedlyAccounts;")) {
|
||||||
|
while (query.next()) {
|
||||||
|
auto* root = new FeedlyServiceRoot();
|
||||||
|
|
||||||
|
root->setId(query.value(0).toInt());
|
||||||
|
root->setAccountId(query.value(0).toInt());
|
||||||
|
root->network()->setUsername(query.value(1).toString());
|
||||||
|
root->network()->setDeveloperAccessToken(query.value(2).toString());
|
||||||
|
root->network()->oauth()->setRefreshToken(query.value(3).toString());
|
||||||
|
root->network()->setBatchSize(query.value(4).toInt());
|
||||||
|
root->updateTitle();
|
||||||
|
|
||||||
|
fillBaseAccountData(db, root);
|
||||||
|
|
||||||
|
roots.append(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qWarningNN << LOGSEC_GMAIL
|
||||||
|
<< "Getting list of activated accounts failed: '"
|
||||||
|
<< query.lastError().text()
|
||||||
|
<< "'.";
|
||||||
|
|
||||||
|
if (ok != nullptr) {
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return roots;
|
||||||
|
}
|
||||||
|
|
||||||
QList<ServiceRoot*> DatabaseQueries::getGmailAccounts(const QSqlDatabase& db, bool* ok) {
|
QList<ServiceRoot*> DatabaseQueries::getGmailAccounts(const QSqlDatabase& db, bool* ok) {
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
QList<ServiceRoot*> roots;
|
QList<ServiceRoot*> roots;
|
||||||
@ -2640,27 +2681,6 @@ bool DatabaseQueries::deleteGmailAccount(const QSqlDatabase& db, int account_id)
|
|||||||
return q.exec();
|
return q.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseQueries::storeNewGmailTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id) {
|
|
||||||
QSqlQuery query(db);
|
|
||||||
|
|
||||||
query.prepare("UPDATE GmailAccounts "
|
|
||||||
"SET refresh_token = :refresh_token "
|
|
||||||
"WHERE id = :id;");
|
|
||||||
query.bindValue(QSL(":refresh_token"), refresh_token);
|
|
||||||
query.bindValue(QSL(":id"), account_id);
|
|
||||||
|
|
||||||
if (query.exec()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
qWarningNN << LOGSEC_GMAIL
|
|
||||||
<< "Updating tokens in DB failed: '"
|
|
||||||
<< query.lastError().text()
|
|
||||||
<< "'.";
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DatabaseQueries::deleteInoreaderAccount(const QSqlDatabase& db, int account_id) {
|
bool DatabaseQueries::deleteInoreaderAccount(const QSqlDatabase& db, int account_id) {
|
||||||
QSqlQuery q(db);
|
QSqlQuery q(db);
|
||||||
|
|
||||||
@ -2670,23 +2690,22 @@ bool DatabaseQueries::deleteInoreaderAccount(const QSqlDatabase& db, int account
|
|||||||
return q.exec();
|
return q.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DatabaseQueries::storeNewInoreaderTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id) {
|
bool DatabaseQueries::storeNewOauthTokens(const QSqlDatabase& db, const QString& table_name,
|
||||||
|
const QString& refresh_token, int account_id) {
|
||||||
QSqlQuery query(db);
|
QSqlQuery query(db);
|
||||||
|
|
||||||
query.prepare("UPDATE InoreaderAccounts "
|
query.prepare(QSL("UPDATE %1 "
|
||||||
"SET refresh_token = :refresh_token "
|
"SET refresh_token = :refresh_token "
|
||||||
"WHERE id = :id;");
|
"WHERE id = :id;").arg(table_name));
|
||||||
query.bindValue(QSL(":refresh_token"), refresh_token);
|
query.bindValue(QSL(":refresh_token"), refresh_token);
|
||||||
query.bindValue(QSL(":id"), account_id);
|
query.bindValue(QSL(":id"), account_id);
|
||||||
|
|
||||||
if (query.exec()) {
|
if (query.exec()) {
|
||||||
|
qDebugNN << LOGSEC_DB << "Stored new refresh token into table" << QUOTE_W_SPACE_DOT(table_name);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qWarningNN << LOGSEC_INOREADER
|
qWarningNN << LOGSEC_DB << "Updating tokens in DB failed:" << QUOTE_W_SPACE_DOT(query.lastError().text());
|
||||||
<< "Updating tokens in DB failed: '"
|
|
||||||
<< query.lastError().text()
|
|
||||||
<< "'.";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,8 @@ class DatabaseQueries {
|
|||||||
bool* ok = nullptr);
|
bool* ok = nullptr);
|
||||||
|
|
||||||
// Common account methods.
|
// Common account methods.
|
||||||
|
static bool storeNewOauthTokens(const QSqlDatabase& db, const QString& table_name,
|
||||||
|
const QString& refresh_token, int account_id);
|
||||||
static void fillBaseAccountData(const QSqlDatabase& db, ServiceRoot* account, bool* ok = nullptr);
|
static void fillBaseAccountData(const QSqlDatabase& db, ServiceRoot* account, bool* ok = nullptr);
|
||||||
static int createBaseAccount(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
|
static int createBaseAccount(const QSqlDatabase& db, const QString& code, bool* ok = nullptr);
|
||||||
static void editBaseAccount(const QSqlDatabase& db, ServiceRoot* account, bool* ok = nullptr);
|
static void editBaseAccount(const QSqlDatabase& db, ServiceRoot* account, bool* ok = nullptr);
|
||||||
@ -151,6 +153,7 @@ class DatabaseQueries {
|
|||||||
static void fillFeedData(T* feed, const QSqlRecord& sql_record);
|
static void fillFeedData(T* feed, const QSqlRecord& sql_record);
|
||||||
|
|
||||||
// Feedly account.
|
// Feedly account.
|
||||||
|
static QList<ServiceRoot*> getFeedlyAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
||||||
static bool createFeedlyAccount(const QSqlDatabase& db,
|
static bool createFeedlyAccount(const QSqlDatabase& db,
|
||||||
const QString& username,
|
const QString& username,
|
||||||
const QString& developer_access_token,
|
const QString& developer_access_token,
|
||||||
@ -199,7 +202,6 @@ class DatabaseQueries {
|
|||||||
// Gmail account.
|
// Gmail account.
|
||||||
static QStringList getAllRecipients(const QSqlDatabase& db, int account_id);
|
static QStringList getAllRecipients(const QSqlDatabase& db, int account_id);
|
||||||
static bool deleteGmailAccount(const QSqlDatabase& db, int account_id);
|
static bool deleteGmailAccount(const QSqlDatabase& db, int account_id);
|
||||||
static bool storeNewGmailTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id);
|
|
||||||
static QList<ServiceRoot*> getGmailAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
static QList<ServiceRoot*> getGmailAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
||||||
static bool overwriteGmailAccount(const QSqlDatabase& db, const QString& username, const QString& app_id,
|
static bool overwriteGmailAccount(const QSqlDatabase& db, const QString& username, const QString& app_id,
|
||||||
const QString& app_key, const QString& redirect_url, const QString& refresh_token,
|
const QString& app_key, const QString& redirect_url, const QString& refresh_token,
|
||||||
@ -210,7 +212,6 @@ class DatabaseQueries {
|
|||||||
|
|
||||||
// Inoreader account.
|
// Inoreader account.
|
||||||
static bool deleteInoreaderAccount(const QSqlDatabase& db, int account_id);
|
static bool deleteInoreaderAccount(const QSqlDatabase& db, int account_id);
|
||||||
static bool storeNewInoreaderTokens(const QSqlDatabase& db, const QString& refresh_token, int account_id);
|
|
||||||
static QList<ServiceRoot*> getInoreaderAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
static QList<ServiceRoot*> getInoreaderAccounts(const QSqlDatabase& db, bool* ok = nullptr);
|
||||||
static bool overwriteInoreaderAccount(const QSqlDatabase& db, const QString& username, const QString& app_id,
|
static bool overwriteInoreaderAccount(const QSqlDatabase& db, const QString& username, const QString& app_id,
|
||||||
const QString& app_key, const QString& redirect_url, const QString& refresh_token,
|
const QString& app_key, const QString& redirect_url, const QString& refresh_token,
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#define FEEDLY_DEFINITIONS_H
|
#define FEEDLY_DEFINITIONS_H
|
||||||
|
|
||||||
#define FEEDLY_UNLIMITED_BATCH_SIZE -1
|
#define FEEDLY_UNLIMITED_BATCH_SIZE -1
|
||||||
|
#define FEEDLY_MAX_BATCH_SIZE 999
|
||||||
|
|
||||||
#define FEEDLY_GENERATE_DAT "https://feedly.com/v3/auth/dev"
|
#define FEEDLY_GENERATE_DAT "https://feedly.com/v3/auth/dev"
|
||||||
|
|
||||||
#define FEEDLY_API_REDIRECT_URI_PORT 8080
|
#define FEEDLY_API_REDIRECT_URI_PORT 8080
|
||||||
|
@ -19,9 +19,7 @@ ServiceRoot* FeedlyEntryPoint::createNewRoot() const {
|
|||||||
QList<ServiceRoot*> FeedlyEntryPoint::initializeSubtree() const {
|
QList<ServiceRoot*> FeedlyEntryPoint::initializeSubtree() const {
|
||||||
QSqlDatabase database = qApp->database()->connection(QSL("FeedlyEntryPoint"));
|
QSqlDatabase database = qApp->database()->connection(QSL("FeedlyEntryPoint"));
|
||||||
|
|
||||||
return {};
|
return DatabaseQueries::getFeedlyAccounts(database);
|
||||||
|
|
||||||
//return DatabaseQueries::getGreaderAccounts(database);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FeedlyEntryPoint::name() const {
|
QString FeedlyEntryPoint::name() const {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include "miscellaneous/application.h"
|
#include "miscellaneous/application.h"
|
||||||
#include "network-web/networkfactory.h"
|
#include "network-web/networkfactory.h"
|
||||||
|
|
||||||
|
#include "miscellaneous/databasequeries.h"
|
||||||
#include "network-web/webfactory.h"
|
#include "network-web/webfactory.h"
|
||||||
#include "services/abstract/category.h"
|
#include "services/abstract/category.h"
|
||||||
#include "services/abstract/label.h"
|
#include "services/abstract/label.h"
|
||||||
@ -39,7 +40,7 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
|
|||||||
|
|
||||||
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
|
||||||
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);
|
||||||
connect(m_oauth, &OAuth2Service::tokensRetrieved, this, &FeedlyNetwork::ontokensRetrieved);
|
connect(m_oauth, &OAuth2Service::tokensRetrieved, this, &FeedlyNetwork::onTokensRetrieved);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,8 +108,7 @@ void FeedlyNetwork::onTokensError(const QString& error, const QString& error_des
|
|||||||
QSystemTrayIcon::MessageIcon::Critical,
|
QSystemTrayIcon::MessageIcon::Critical,
|
||||||
nullptr, false,
|
nullptr, false,
|
||||||
[this]() {
|
[this]() {
|
||||||
m_oauth->setAccessToken({});
|
m_oauth->logout(false);
|
||||||
m_oauth->setRefreshToken({});
|
|
||||||
m_oauth->login();
|
m_oauth->login();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -119,19 +119,19 @@ void FeedlyNetwork::onAuthFailed() {
|
|||||||
QSystemTrayIcon::MessageIcon::Critical,
|
QSystemTrayIcon::MessageIcon::Critical,
|
||||||
nullptr, false,
|
nullptr, false,
|
||||||
[this]() {
|
[this]() {
|
||||||
|
m_oauth->logout(false);
|
||||||
m_oauth->login();
|
m_oauth->login();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedlyNetwork::ontokensRetrieved(const QString& access_token, const QString& refresh_token, int expires_in) {
|
void FeedlyNetwork::onTokensRetrieved(const QString& access_token, const QString& refresh_token, int expires_in) {
|
||||||
Q_UNUSED(expires_in)
|
Q_UNUSED(expires_in)
|
||||||
Q_UNUSED(access_token)
|
Q_UNUSED(access_token)
|
||||||
|
|
||||||
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
|
|
||||||
//DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId());
|
DatabaseQueries::storeNewOauthTokens(database, QSL("FeedlyAccounts"), refresh_token, m_service->accountId());
|
||||||
|
|
||||||
qApp->showGuiMessage(tr("Logged in successfully"),
|
qApp->showGuiMessage(tr("Logged in successfully"),
|
||||||
tr("Your login to Feedly was authorized."),
|
tr("Your login to Feedly was authorized."),
|
||||||
QSystemTrayIcon::MessageIcon::Information);
|
QSystemTrayIcon::MessageIcon::Information);
|
||||||
|
@ -42,7 +42,7 @@ class FeedlyNetwork : public QObject {
|
|||||||
private slots:
|
private slots:
|
||||||
void onTokensError(const QString& error, const QString& error_description);
|
void onTokensError(const QString& error, const QString& error_description);
|
||||||
void onAuthFailed();
|
void onAuthFailed();
|
||||||
void ontokensRetrieved(const QString& access_token, const QString& refresh_token, int expires_in);
|
void onTokensRetrieved(const QString& access_token, const QString& refresh_token, int expires_in);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -66,7 +66,7 @@ void FeedlyServiceRoot::start(bool freshly_activated) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString FeedlyServiceRoot::code() const {
|
QString FeedlyServiceRoot::code() const {
|
||||||
return FeedlyServiceRoot().code();
|
return FeedlyEntryPoint().code();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FeedlyServiceRoot::saveAllCachedData(bool ignore_errors) {
|
void FeedlyServiceRoot::saveAllCachedData(bool ignore_errors) {
|
||||||
|
@ -60,6 +60,10 @@ FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) {
|
|||||||
connect(m_ui.m_txtDeveloperAccessToken->lineEdit(), &BaseLineEdit::textChanged,
|
connect(m_ui.m_txtDeveloperAccessToken->lineEdit(), &BaseLineEdit::textChanged,
|
||||||
this, &FeedlyAccountDetails::onDeveloperAccessTokenChanged);
|
this, &FeedlyAccountDetails::onDeveloperAccessTokenChanged);
|
||||||
|
|
||||||
|
m_ui.m_spinLimitMessages->setMinimum(FEEDLY_UNLIMITED_BATCH_SIZE);
|
||||||
|
m_ui.m_spinLimitMessages->setMaximum(FEEDLY_MAX_BATCH_SIZE);
|
||||||
|
m_ui.m_spinLimitMessages->setValue(FEEDLY_UNLIMITED_BATCH_SIZE);
|
||||||
|
|
||||||
setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_btnGetToken);
|
setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_btnGetToken);
|
||||||
setTabOrder(m_ui.m_btnGetToken, m_ui.m_txtDeveloperAccessToken->lineEdit());
|
setTabOrder(m_ui.m_btnGetToken, m_ui.m_txtDeveloperAccessToken->lineEdit());
|
||||||
setTabOrder(m_ui.m_txtDeveloperAccessToken->lineEdit(), m_ui.m_spinLimitMessages);
|
setTabOrder(m_ui.m_txtDeveloperAccessToken->lineEdit(), m_ui.m_spinLimitMessages);
|
||||||
|
@ -36,8 +36,10 @@ void FormEditFeedlyAccount::apply() {
|
|||||||
m_details->m_oauth->logout();
|
m_details->m_oauth->logout();
|
||||||
m_details->m_oauth->deleteLater();
|
m_details->m_oauth->deleteLater();
|
||||||
|
|
||||||
// Force live OAuth object to re-start it's
|
// Force live OAuth object to re-start it's redirection handler.
|
||||||
account<FeedlyServiceRoot>()->network()->oauth()->setRedirectUrl(account<FeedlyServiceRoot>()->network()->oauth()->redirectUrl());
|
account<FeedlyServiceRoot>()->network()->oauth()->setRedirectUrl(QString(OAUTH_REDIRECT_URI) +
|
||||||
|
QL1C(':') +
|
||||||
|
QString::number(FEEDLY_API_REDIRECT_URI_PORT));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -126,8 +126,8 @@ void GmailNetworkFactory::initializeOauth() {
|
|||||||
|
|
||||||
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
DatabaseQueries::storeNewGmailTokens(database, refresh_token, m_service->accountId());
|
|
||||||
|
|
||||||
|
DatabaseQueries::storeNewOauthTokens(database, QSL("GmailAccounts"), refresh_token, m_service->accountId());
|
||||||
qApp->showGuiMessage(tr("Logged in successfully"),
|
qApp->showGuiMessage(tr("Logged in successfully"),
|
||||||
tr("Your login to Gmail was authorized."),
|
tr("Your login to Gmail was authorized."),
|
||||||
QSystemTrayIcon::MessageIcon::Information);
|
QSystemTrayIcon::MessageIcon::Information);
|
||||||
|
@ -61,8 +61,8 @@ void InoreaderNetworkFactory::initializeOauth() {
|
|||||||
|
|
||||||
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
if (m_service != nullptr && !refresh_token.isEmpty()) {
|
||||||
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
|
||||||
DatabaseQueries::storeNewInoreaderTokens(database, refresh_token, m_service->accountId());
|
|
||||||
|
|
||||||
|
DatabaseQueries::storeNewOauthTokens(database, QSL("InoreaderAccounts"), refresh_token, m_service->accountId());
|
||||||
qApp->showGuiMessage(tr("Logged in successfully"),
|
qApp->showGuiMessage(tr("Logged in successfully"),
|
||||||
tr("Your login to Inoreader was authorized."),
|
tr("Your login to Inoreader was authorized."),
|
||||||
QSystemTrayIcon::MessageIcon::Information);
|
QSystemTrayIcon::MessageIcon::Information);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user