This commit is contained in:
Martin Rotter 2021-02-09 14:44:44 +01:00
parent 795e1b2f72
commit 9e7409e9d3
7 changed files with 107 additions and 28 deletions

View File

@ -9,6 +9,7 @@
#include "miscellaneous/textfactory.h"
#include "network-web/oauth2service.h"
#include "services/abstract/category.h"
#include "services/feedly/definitions.h"
#include "services/gmail/definitions.h"
#include "services/gmail/gmailfeed.h"
#include "services/gmail/gmailserviceroot.h"
@ -1841,6 +1842,36 @@ bool DatabaseQueries::overwriteOwnCloudAccount(const QSqlDatabase& db, const QSt
}
}
bool DatabaseQueries::createFeedlyAccount(const QSqlDatabase& db, const QString& username,
const QString& developer_access_token, const QString& refresh_token,
int batch_size, int id_to_assign) {
QSqlQuery q(db);
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);");
q.bindValue(QSL(":id"), id_to_assign);
q.bindValue(QSL(":username"), username);
q.bindValue(QSL(":developer_access_token"), developer_access_token);
q.bindValue(QSL(":refresh_token"), refresh_token);
q.bindValue(QSL(":msg_limit"), batch_size <= 0 ? FEEDLY_UNLIMITED_BATCH_SIZE : batch_size);
if (q.exec()) {
return true;
}
else {
qWarningNN << LOGSEC_FEEDLY
<< "Inserting of new account failed:"
<< QUOTE_W_SPACE_DOT(q.lastError().text());
return false;
}
}
bool DatabaseQueries::overwriteFeedlyAccount(const QSqlDatabase& db, const QString& username,
const QString& developer_access_token, const QString& refresh_token,
int batch_size, int id_to_assign) {
return {};
}
bool DatabaseQueries::createGreaderAccount(const QSqlDatabase& db, int id_to_assign, const QString& username,
const QString& password, GreaderServiceRoot::Service service,
const QString& url, int batch_size) {

View File

@ -150,6 +150,20 @@ class DatabaseQueries {
template<typename T>
static void fillFeedData(T* feed, const QSqlRecord& sql_record);
// Feedly account.
static bool createFeedlyAccount(const QSqlDatabase& db,
const QString& username,
const QString& developer_access_token,
const QString& refresh_token,
int batch_size,
int id_to_assign);
static bool overwriteFeedlyAccount(const QSqlDatabase& db,
const QString& username,
const QString& developer_access_token,
const QString& refresh_token,
int batch_size,
int id_to_assign);
// Greader account.
static bool deleteGreaderAccount(const QSqlDatabase& db, int account_id);
static QList<ServiceRoot*> getGreaderAccounts(const QSqlDatabase& db, bool* ok = nullptr);

View File

@ -27,15 +27,15 @@ FeedlyNetwork::FeedlyNetwork(QObject* parent)
#if defined (FEEDLY_OFFICIAL_SUPPORT)
m_oauth(new OAuth2Service(QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_AUTH,
QSL(FEEDLY_API_URL_BASE) + FEEDLY_API_URL_TOKEN,
"dontknow",
"dontknow",
FEEDLY_CLIENT_ID,
FEEDLY_CLIENT_ID,
FEEDLY_API_SCOPE, this)),
#endif
m_username(QString()),
m_developerAccessToken(QString()), m_batchSize(FEEDLY_UNLIMITED_BATCH_SIZE) {
#if defined (FEEDLY_OFFICIAL_SUPPORT)
//m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
m_oauth->setRedirectUrl(QString(OAUTH_REDIRECT_URI) + QL1C(':') + QString::number(FEEDLY_API_REDIRECT_URI_PORT));
connect(m_oauth, &OAuth2Service::tokensRetrieveError, this, &FeedlyNetwork::onTokensError);
connect(m_oauth, &OAuth2Service::authFailed, this, &FeedlyNetwork::onAuthFailed);

View File

@ -15,6 +15,10 @@
#include "services/feedly/feedlynetwork.h"
#include "services/feedly/gui/formeditfeedlyaccount.h"
#if defined (FEEDLY_OFFICIAL_SUPPORT)
#include "network-web/oauth2service.h"
#endif
FeedlyServiceRoot::FeedlyServiceRoot(RootItem* parent)
: ServiceRoot(parent), m_network(new FeedlyNetwork(this)) {
setIcon(FeedlyEntryPoint().icon());
@ -76,23 +80,35 @@ void FeedlyServiceRoot::updateTitle() {
void FeedlyServiceRoot::saveAccountDataToDatabase(bool creating_new) {
QSqlDatabase database = qApp->database()->connection(metaObject()->className());
/*
if (!creating_new) {
if (DatabaseQueries::overwriteGreaderAccount(database, m_network->username(),
m_network->password(), m_network->service(),
m_network->baseUrl(), m_network->batchSize(),
accountId())) {
if (!creating_new) {
if (DatabaseQueries::overwriteFeedlyAccount(database,
m_network->username(),
m_network->developerAccessToken(),
#if defined (FEEDLY_OFFICIAL_SUPPORT)
m_network->oauth()->refreshToken(),
#else
{},
#endif
m_network->batchSize(),
accountId())) {
updateTitle();
itemChanged(QList<RootItem*>() << this);
}
}
else {
if (DatabaseQueries::createGreaderAccount(database, accountId(), m_network->username(),
m_network->password(), m_network->service(),
m_network->baseUrl(), m_network->batchSize())) {
}
}
else {
if (DatabaseQueries::createFeedlyAccount(database,
m_network->username(),
m_network->developerAccessToken(),
#if defined (FEEDLY_OFFICIAL_SUPPORT)
m_network->oauth()->refreshToken(),
#else
{},
#endif
m_network->batchSize(),
accountId())) {
updateTitle();
}
}*/
}
}
}
RootItem* FeedlyServiceRoot::obtainNewTreeForSyncIn() const {

View File

@ -27,10 +27,15 @@ void FormEditFeedlyAccount::apply() {
bool editing_account = !applyInternal<FeedlyServiceRoot>();
#if defined (FEEDLY_OFFICIAL_SUPPORT)
// We copy credentials from testing OAuth to live OAuth.
account<FeedlyServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
account<FeedlyServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
account<FeedlyServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
if (!editing_account) {
// We transfer refresh token to avoid the need to login once more,
// then we delete testing OAuth service.
account<FeedlyServiceRoot>()->network()->oauth()->setAccessToken(m_details->m_oauth->accessToken());
account<FeedlyServiceRoot>()->network()->oauth()->setRefreshToken(m_details->m_oauth->refreshToken());
account<FeedlyServiceRoot>()->network()->oauth()->setTokensExpireIn(m_details->m_oauth->tokensExpireIn());
m_details->m_oauth->logout();
m_details->m_oauth->deleteLater();
}
#endif
account<FeedlyServiceRoot>()->network()->setUsername(m_details->m_ui.m_txtUsername->lineEdit()->text());
@ -49,16 +54,20 @@ void FormEditFeedlyAccount::apply() {
void FormEditFeedlyAccount::setEditableAccount(ServiceRoot* editable_account) {
FormAccountDetails::setEditableAccount(editable_account);
FeedlyServiceRoot* existing_root = account<FeedlyServiceRoot>();
#if defined (FEEDLY_OFFICIAL_SUPPORT)
if (m_details->m_oauth != nullptr) {
// We will use live OAuth service for testing.
m_details->m_oauth->logout();
m_details->m_oauth->deleteLater();
}
m_details->m_oauth = account<FeedlyServiceRoot>()->network()->oauth();
m_details->hookNetwork();
#endif
m_details->m_ui.m_txtUsername->lineEdit()->setText(existing_root->network()->username());
m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->setText(existing_root->network()->developerAccessToken());
m_details->m_ui.m_spinLimitMessages->setValue(existing_root->network()->batchSize());
m_details->m_ui.m_txtUsername->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->username());
m_details->m_ui.m_txtDeveloperAccessToken->lineEdit()->setText(account<FeedlyServiceRoot>()->network()->developerAccessToken());
m_details->m_ui.m_spinLimitMessages->setValue(account<FeedlyServiceRoot>()->network()->batchSize());
}
void FormEditFeedlyAccount::performTest() {

View File

@ -31,6 +31,12 @@ class GmailAccountDetails : public QWidget {
private:
Ui::GmailAccountDetails m_ui;
// Testing OAuth service. This object is not ever copied
// to new living account instance, instead only its properties
// like tokens are copied.
// If editing existing account, then the pointer points
// directly to existing OAuth from the account.
OAuth2Service* m_oauth;
};

View File

@ -32,8 +32,11 @@ class InoreaderAccountDetails : public QWidget {
private:
Ui::InoreaderAccountDetails m_ui;
// Testing OAuth service. Only for testing. Resulting tokens
//
// Testing OAuth service. This object is not ever copied
// to new living account instance, instead only its properties
// like tokens are copied.
// If editing existing account, then the pointer points
// directly to existing OAuth from the account.
OAuth2Service* m_oauth;
};