From 2cf7797ce06bf6449ee37fd14540c68427c2f9e5 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 24 Feb 2021 14:22:40 +0100 Subject: [PATCH] save work --- src/librssguard/definitions/definitions.h | 1 + src/librssguard/miscellaneous/textfactory.cpp | 8 ++--- src/librssguard/miscellaneous/textfactory.h | 4 +-- .../feedly/gui/feedlyaccountdetails.cpp | 6 ++-- .../gmail/gui/gmailaccountdetails.cpp | 30 +++++++++++++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index da51b014b..93c7dfa95 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -19,6 +19,7 @@ #define ARGUMENTS_LIST_SEPARATOR "\n" +#define OAUTH_DECRYPTION_KEY 11451167756100761335ul #define ADBLOCK_HOWTO_FILTERS "https://help.eyeo.com/en/adblockplus/how-to-write-filters" #define ADBLOCK_UPDATE_DAYS_INTERVAL 14 #define ADBLOCK_ICON_ACTIVE "adblock" diff --git a/src/librssguard/miscellaneous/textfactory.cpp b/src/librssguard/miscellaneous/textfactory.cpp index 01b9e87f1..803908d65 100755 --- a/src/librssguard/miscellaneous/textfactory.cpp +++ b/src/librssguard/miscellaneous/textfactory.cpp @@ -133,12 +133,12 @@ QDateTime TextFactory::parseDateTime(qint64 milis_from_epoch) { return QDateTime::fromMSecsSinceEpoch(milis_from_epoch, Qt::TimeSpec::UTC); } -QString TextFactory::encrypt(const QString& text) { - return SimpleCrypt(initializeSecretEncryptionKey()).encryptToString(text); +QString TextFactory::encrypt(const QString& text, quint64 key) { + return SimpleCrypt(key == 0 ? initializeSecretEncryptionKey() : key).encryptToString(text); } -QString TextFactory::decrypt(const QString& text) { - return SimpleCrypt(initializeSecretEncryptionKey()).decryptToString(text); +QString TextFactory::decrypt(const QString& text, quint64 key) { + return SimpleCrypt(key == 0 ? initializeSecretEncryptionKey() : key).decryptToString(text); } QString TextFactory::newline() { diff --git a/src/librssguard/miscellaneous/textfactory.h b/src/librssguard/miscellaneous/textfactory.h index cb9159c80..c091f50e9 100755 --- a/src/librssguard/miscellaneous/textfactory.h +++ b/src/librssguard/miscellaneous/textfactory.h @@ -28,8 +28,8 @@ class TextFactory { // Converts 1970-epoch miliseconds to date/time. // NOTE: This method tries to always return time in UTC. static QDateTime parseDateTime(qint64 milis_from_epoch); - static QString encrypt(const QString& text); - static QString decrypt(const QString& text); + static QString encrypt(const QString& text, quint64 key = 0); + static QString decrypt(const QString& text, quint64 key = 0); static QString newline(); // Shortens input string according to given length limit. diff --git a/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp b/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp index b63159afd..3ea3bd7fd 100755 --- a/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp +++ b/src/librssguard/services/feedly/gui/feedlyaccountdetails.cpp @@ -11,14 +11,14 @@ #include "services/feedly/definitions.h" #include "services/feedly/feedlynetwork.h" -#if defined (FEEDLY_OFFICIAL_SUPPORT) +#if defined(FEEDLY_OFFICIAL_SUPPORT) #include "network-web/oauth2service.h" #endif #include FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) { -#if defined (FEEDLY_OFFICIAL_SUPPORT) +#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, FEEDLY_CLIENT_ID, @@ -37,7 +37,7 @@ FeedlyAccountDetails::FeedlyAccountDetails(QWidget* parent) : QWidget(parent) { tr("No test done yet."), tr("Here, results of connection test are shown.")); -#if defined (FEEDLY_OFFICIAL_SUPPORT) +#if defined(FEEDLY_OFFICIAL_SUPPORT) m_ui.m_lblInfo->setText(tr("Your %1 build has official Feedly support. You do not have to use \"developer acess " "token\". You can therefore leave corresponding field empty.").arg(APP_NAME)); #else diff --git a/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp b/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp index b391a8908..3adf4ca37 100644 --- a/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp +++ b/src/librssguard/services/gmail/gui/gmailaccountdetails.cpp @@ -16,8 +16,15 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent) GuiUtilities::setLabelAsNotice(*m_ui.m_lblInfo, true); - m_ui.m_lblInfo->setText(tr("Specified redirect URL must start with \"http://localhost\" and " - "must be configured in your OAuth \"application\".")); +#if defined(GMAIL_OFFICIAL_SUPPORT) + m_ui.m_lblInfo->setText(tr("There are some preconfigured OAuth tokens so you do not have to fill in your " + "client ID/secret, but it is strongly recommended to obtain your " + "own as it preconfigured tokens have limited global usage quota. If you wash " + "to use preconfigured tokens, simply leave those fields empty and make sure " + "to leave default value of redirect URL.")); +#else + m_ui.m_lblInfo->setText(tr("You have to fill in your client ID/secret and also fill in correct redirect URL.")); +#endif m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information, tr("Not tested yet."), @@ -55,8 +62,21 @@ GmailAccountDetails::GmailAccountDetails(QWidget* parent) void GmailAccountDetails::testSetup() { m_oauth->logout(); + +#if defined(GMAIL_OFFICIAL_SUPPORT) + if (m_ui.m_txtAppId->lineEdit()->text().isEmpty() || m_ui.m_txtAppKey->lineEdit()->text().isEmpty()) { + m_oauth->setClientId(TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY)); + m_oauth->setClientSecret(TextFactory::decrypt(GMAIL_CLIENT_ID, OAUTH_DECRYPTION_KEY)); + } + else { +#endif m_oauth->setClientId(m_ui.m_txtAppId->lineEdit()->text()); m_oauth->setClientSecret(m_ui.m_txtAppKey->lineEdit()->text()); + +#if defined(GMAIL_OFFICIAL_SUPPORT) +} +#endif + m_oauth->setRedirectUrl(m_ui.m_txtRedirectUrl->lineEdit()->text()); if (m_oauth->login()) { @@ -85,7 +105,7 @@ void GmailAccountDetails::onAuthError(const QString& error, const QString& detai Q_UNUSED(error) m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Error, - tr("There is error. %1 ").arg(detailed_description), + tr("There is error: %1").arg(detailed_description), tr("There was error during testing.")); } @@ -110,7 +130,11 @@ void GmailAccountDetails::checkOAuthValue(const QString& value) { if (line_edit != nullptr) { if (value.isEmpty()) { +#if defined(GMAIL_OFFICIAL_SUPPORT) + line_edit->setStatus(WidgetWithStatus::StatusType::Ok, tr("Preconfigured client ID/secret will be used.")); +#else line_edit->setStatus(WidgetWithStatus::StatusType::Error, tr("Empty value is entered.")); +#endif } else { line_edit->setStatus(WidgetWithStatus::StatusType::Ok, tr("Some value is entered."));