From b8da3afffb840292f68f3ed9ebfa4b55a2bf0070 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 25 Feb 2021 20:08:09 +0100 Subject: [PATCH] fix functor crash --- src/librssguard/network-web/oauth2service.cpp | 11 ++++++----- src/librssguard/network-web/oauth2service.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librssguard/network-web/oauth2service.cpp b/src/librssguard/network-web/oauth2service.cpp index a20401e0b..4dab03e01 100644 --- a/src/librssguard/network-web/oauth2service.cpp +++ b/src/librssguard/network-web/oauth2service.cpp @@ -48,7 +48,7 @@ OAuth2Service::OAuth2Service(const QString& auth_url, const QString& token_url, : QObject(parent), m_id(QString::number(QRandomGenerator::global()->generate())), m_timerId(-1), m_redirectionHandler(new OAuthHttpHandler(tr("You can close this window now. Go back to %1.").arg(APP_NAME), this)), - m_functorOnLogin({}) { + m_functorOnLogin(std::function()) { m_tokenGrantType = QSL("authorization_code"); m_tokenUrl = QUrl(token_url); m_authUrl = auth_url; @@ -230,7 +230,10 @@ void OAuth2Service::tokenRequestFinished(QNetworkReply* network_reply) { << "Obtained refresh token" << QUOTE_W_SPACE(refreshToken()) << "- expires on date/time" << QUOTE_W_SPACE_DOT(tokensExpireIn()); - m_functorOnLogin(); + if (m_functorOnLogin != nullptr) { + m_functorOnLogin(); + } + emit tokensRetrieved(accessToken(), refreshToken(), expires); } @@ -300,7 +303,7 @@ void OAuth2Service::setRefreshToken(const QString& refresh_token) { } bool OAuth2Service::login(const std::function& functor_when_logged_in) { - m_functorOnLogin = {}; + m_functorOnLogin = functor_when_logged_in; if (!m_redirectionHandler->isListening()) { qCriticalNN << LOGSEC_OAUTH @@ -316,8 +319,6 @@ bool OAuth2Service::login(const std::function& functor_when_logged_in) { bool did_token_expire = tokensExpireIn().isNull() || tokensExpireIn() < QDateTime::currentDateTime().addSecs(-120); bool does_token_exist = !refreshToken().isEmpty(); - m_functorOnLogin = functor_when_logged_in; - // We refresh current tokens only if: // 1. We have some existing refresh token. // AND diff --git a/src/librssguard/network-web/oauth2service.h b/src/librssguard/network-web/oauth2service.h index 093c6c32d..4205aaf3c 100644 --- a/src/librssguard/network-web/oauth2service.h +++ b/src/librssguard/network-web/oauth2service.h @@ -99,7 +99,7 @@ class OAuth2Service : public QObject { // // Returns true, if user is already logged in (final state). // Returns false, if user is NOT logged in (asynchronous flow). - bool login(const std::function& functor_when_logged_in = {}); + bool login(const std::function& functor_when_logged_in = std::function()); // Removes all state data and stops redirection handler. void logout(bool stop_redirection_handler = true);