Do not store access token, prepare DB for Inoreader multi acc.

This commit is contained in:
Martin Rotter 2017-10-02 12:44:54 +02:00
parent 4dab74c13c
commit 11e816bdf6
6 changed files with 146 additions and 66 deletions

View File

@ -43,6 +43,7 @@
#include "definitions/definitions.h" #include "definitions/definitions.h"
#include "gui/dialogs/oauthlogin.h" #include "gui/dialogs/oauthlogin.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "services/inoreader/definitions.h"
#include <QDebug> #include <QDebug>
#include <QJsonDocument> #include <QJsonDocument>
@ -53,7 +54,7 @@
OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId, OAuth2Service::OAuth2Service(QString authUrl, QString tokenUrl, QString clientId,
QString clientSecret, QString scope, QObject* parent) QString clientSecret, QString scope, QObject* parent)
: QObject(parent), m_tokensExpireIn(QDateTime()) { : QObject(parent), m_tokensExpireIn(QDateTime()) {
m_redirectUri = QSL("http://localhost"); m_redirectUri = QSL(INOREADER_OAUTH_CLI_REDIRECT);
m_tokenGrantType = QSL("authorization_code"); m_tokenGrantType = QSL("authorization_code");
m_tokenUrl = QUrl(tokenUrl); m_tokenUrl = QUrl(tokenUrl);
m_authUrl = authUrl; m_authUrl = authUrl;

View File

@ -22,6 +22,8 @@
#define INOREADER_OAUTH_SCOPE "read write" #define INOREADER_OAUTH_SCOPE "read write"
#define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token" #define INOREADER_OAUTH_TOKEN_URL "https://www.inoreader.com/oauth2/token"
#define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth" #define INOREADER_OAUTH_AUTH_URL "https://www.inoreader.com/oauth2/auth"
#define INOREADER_OAUTH_CLI_REDIRECT "http://localhost"
#define INOREADER_OAUTH_CLI_ID "1000000604" #define INOREADER_OAUTH_CLI_ID "1000000604"
#define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK" #define INOREADER_OAUTH_CLI_KEY "gsStoZ3aAoQJCgQxoFSuXkWI7Sly87yK"

View File

@ -28,17 +28,26 @@
FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent), FormEditInoreaderAccount::FormEditInoreaderAccount(QWidget* parent) : QDialog(parent),
m_network(nullptr), m_editableRoot(nullptr) { m_network(nullptr), m_editableRoot(nullptr) {
m_ui.setupUi(this); m_ui.setupUi(this);
GuiUtilities::setLabelAsNotice(*m_ui.m_lblAuthInfo, true);
GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("inoreader"))); GuiUtilities::applyDialogProperties(*this, qApp->icons()->miscIcon(QSL("inoreader")));
m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information, m_ui.m_lblTestResult->setStatus(WidgetWithStatus::StatusType::Information,
tr("Not tested yet."), tr("Not tested yet."),
tr("Not tested yet.")); tr("Not tested yet."));
m_ui.m_lblTestResult->label()->setWordWrap(true); m_ui.m_lblTestResult->label()->setWordWrap(true);
m_ui.m_txtUsername->lineEdit()->setPlaceholderText(tr("User-visible username")); m_ui.m_txtUsername->lineEdit()->setPlaceholderText(tr("User-visible username"));
setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_spinLimitMessages); setTabOrder(m_ui.m_txtUsername->lineEdit(), m_ui.m_txtAppId);
setTabOrder(m_ui.m_txtAppId, m_ui.m_txtAppKey);
setTabOrder(m_ui.m_txtAppKey, m_ui.m_txtRedirectUrl);
setTabOrder(m_ui.m_txtRedirectUrl, m_ui.m_spinLimitMessages);
setTabOrder(m_ui.m_spinLimitMessages, m_ui.m_btnTestSetup); setTabOrder(m_ui.m_spinLimitMessages, m_ui.m_btnTestSetup);
setTabOrder(m_ui.m_btnTestSetup, m_ui.m_buttonBox); setTabOrder(m_ui.m_btnTestSetup, m_ui.m_buttonBox);
connect(m_ui.m_txtAppId->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue);
connect(m_ui.m_txtAppKey->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue);
connect(m_ui.m_txtRedirectUrl->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkOAuthValue);
connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkUsername); connect(m_ui.m_txtUsername->lineEdit(), &BaseLineEdit::textChanged, this, &FormEditInoreaderAccount::checkUsername);
connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup); connect(m_ui.m_btnTestSetup, &QPushButton::clicked, this, &FormEditInoreaderAccount::testSetup);
connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk); connect(m_ui.m_buttonBox, &QDialogButtonBox::accepted, this, &FormEditInoreaderAccount::onClickedOk);
@ -130,9 +139,15 @@ void FormEditInoreaderAccount::unhookNetwork() {
InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() { InoreaderServiceRoot* FormEditInoreaderAccount::execForCreate() {
setWindowTitle(tr("Add new Inoreader account")); setWindowTitle(tr("Add new Inoreader account"));
m_network = new InoreaderNetworkFactory(this); m_network = new InoreaderNetworkFactory(this);
m_ui.m_txtAppId->lineEdit()->setText(INOREADER_OAUTH_CLI_ID);
m_ui.m_txtAppKey->lineEdit()->setText(INOREADER_OAUTH_CLI_KEY);
m_ui.m_txtRedirectUrl->lineEdit()->setText(INOREADER_OAUTH_CLI_REDIRECT);
hookNetwork(); hookNetwork();
exec(); exec();
unhookNetwork(); unhookNetwork();
return m_editableRoot; return m_editableRoot;
} }
@ -147,3 +162,16 @@ void FormEditInoreaderAccount::execForEdit(InoreaderServiceRoot* existing_root)
exec(); exec();
unhookNetwork(); unhookNetwork();
} }
void FormEditInoreaderAccount::checkOAuthValue(const QString& value) {
LineEditWithStatus* line_edit = qobject_cast<LineEditWithStatus*>(sender()->parent());
if (line_edit != nullptr) {
if (value.isEmpty()) {
line_edit->setStatus(WidgetWithStatus::Error, tr("Empty value is entered."));
}
else {
line_edit->setStatus(WidgetWithStatus::Ok, tr("Some value is entered."));
}
}
}

View File

@ -35,7 +35,7 @@ class FormEditInoreaderAccount : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit FormEditInoreaderAccount(QWidget* parent = 0); explicit FormEditInoreaderAccount(QWidget* parent = nullptr);
virtual ~FormEditInoreaderAccount(); virtual ~FormEditInoreaderAccount();
InoreaderServiceRoot* execForCreate(); InoreaderServiceRoot* execForCreate();
@ -46,6 +46,7 @@ class FormEditInoreaderAccount : public QDialog {
void testSetup(); void testSetup();
void onClickedOk(); void onClickedOk();
void onClickedCancel(); void onClickedCancel();
void checkOAuthValue(const QString& value);
void checkUsername(const QString& username); void checkUsername(const QString& username);
void onAuthFailed(); void onAuthFailed();
void onAuthError(const QString& error, const QString& detailed_description); void onAuthError(const QString& error, const QString& detailed_description);

View File

@ -2,79 +2,130 @@
<ui version="4.0"> <ui version="4.0">
<class>FormEditInoreaderAccount</class> <class>FormEditInoreaderAccount</class>
<widget class="QDialog" name="FormEditInoreaderAccount"> <widget class="QDialog" name="FormEditInoreaderAccount">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>542</width>
<height>363</height>
</rect>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Dialog</string> <string>Dialog</string>
</property> </property>
<layout class="QFormLayout" name="formLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item row="0" column="0"> <item>
<widget class="QLabel" name="m_lblUsername"> <layout class="QFormLayout" name="formLayout">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="m_lblUsername">
<property name="text"> <property name="text">
<string>Only download newest X messages per feed</string> <string>Username</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QSpinBox" name="m_spinLimitMessages"> <widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
<property name="maximumSize"> </item>
<size> <item row="1" column="0" colspan="2">
<width>140</width> <widget class="QGroupBox" name="groupBox">
<height>16777215</height> <property name="title">
</size> <string>OAuth 2.0 settings</string>
</property>
<property name="suffix">
<string> message(s)</string>
</property> </property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="m_lblUsername_2">
<property name="text">
<string>Application ID</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtAppId" native="true"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="m_lblUsername_3">
<property name="text">
<string>Application key</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="LineEditWithStatus" name="m_txtAppKey" native="true"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="m_lblUsername_4">
<property name="text">
<string>Redirect URL</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="LineEditWithStatus" name="m_txtRedirectUrl" native="true"/>
</item>
<item row="3" column="0" colspan="2">
<widget class="QLabel" name="m_lblAuthInfo">
<property name="text">
<string>These settings DO NOT have to be changed from their default values. Change these values only of you are advanced user and you know what you are doing!</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Only download newest X messages per feed</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="m_spinLimitMessages">
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="suffix">
<string> message(s)</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="m_btnTestSetup">
<property name="text">
<string>&amp;Login</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item row="3" column="0" colspan="2"> <item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>120</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="m_btnTestSetup">
<property name="text">
<string>&amp;Login</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LabelWithStatus" name="m_lblTestResult" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_buttonBox"> <widget class="QDialogButtonBox" name="m_buttonBox">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -84,9 +135,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<widget class="LineEditWithStatus" name="m_txtUsername" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@ -40,7 +40,7 @@ QList<ServiceRoot*> InoreaderEntryPoint::initializeSubtree() const {
} }
bool InoreaderEntryPoint::isSingleInstanceService() const { bool InoreaderEntryPoint::isSingleInstanceService() const {
return true; return false;
} }
QString InoreaderEntryPoint::name() const { QString InoreaderEntryPoint::name() const {