From b76523ec7598e4619db2a7fa3224f063208cc61c Mon Sep 17 00:00:00 2001 From: Bent Witthold Date: Mon, 27 Apr 2026 08:02:17 +0200 Subject: [PATCH] API authentication token is read from settings and set as bearer token. --- genericcore.cpp | 8 +++++--- network/servercommunicator.cpp | 26 ++++++++++++++++---------- network/servercommunicator.h | 7 +++++-- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/genericcore.cpp b/genericcore.cpp index 9268847..7824d17 100644 --- a/genericcore.cpp +++ b/genericcore.cpp @@ -276,8 +276,10 @@ void GenericCore::applyServerConfiguration() { const QVariantMap serverSettings = SettingsHandler::getSettings("Server"); const QString urlValue = serverSettings.value("url").toString(); if (!urlValue.isEmpty()) { - const QString emailValue = serverSettings.value("email").toString(); - const QString passwordValue = serverSettings.value("password").toString(); - m_serverCommunicator->setServerConfiguration(urlValue, emailValue, passwordValue); + const QString emailValue = serverSettings.value("email").toString(); + const QString passwordValue = serverSettings.value("password").toString(); + const QString authTokenValue = serverSettings.value("authToken").toString(); + m_serverCommunicator->setServerConfiguration(urlValue, emailValue, passwordValue, + authTokenValue); } } diff --git a/network/servercommunicator.cpp b/network/servercommunicator.cpp index 7545e2e..8b683a2 100644 --- a/network/servercommunicator.cpp +++ b/network/servercommunicator.cpp @@ -36,6 +36,21 @@ void ServerCommunicator::setUrl(const QUrl& url) { emit urlChanged(); } +void ServerCommunicator::setServerConfiguration(const QString url, + const QString email, + const QString password, + const QString authToken) { + setUrl(url); + + m_email = email; + m_password = password; + m_authToken = authToken; + + if (!authToken.isEmpty()) { + m_serviceApi->setBearerToken(authToken.toLatin1()); + } +} + void ServerCommunicator::fetchItems() { /// Set up a GET request m_restManager->get(m_serviceApi->createRequest(ROUTE_ITEMS), this, [this](QRestReply& reply) { @@ -94,13 +109,4 @@ void ServerCommunicator::deleteItem(const QString& id) { } reply->deleteLater(); }); -} - -void ServerCommunicator::setServerConfiguration(const QString url, - const QString email, - const QString password) { - setUrl(url); - - m_email = email; - m_password = password; -} +} \ No newline at end of file diff --git a/network/servercommunicator.h b/network/servercommunicator.h index 3107604..83f8be7 100644 --- a/network/servercommunicator.h +++ b/network/servercommunicator.h @@ -16,7 +16,10 @@ class ServerCommunicator : public QObject { QUrl url() const; void setUrl(const QUrl& url); - void setServerConfiguration(const QString url, const QString email, const QString password); + void setServerConfiguration(const QString url, + const QString email, + const QString password, + const QString authToken); public slots: void fetchItems(); @@ -40,7 +43,7 @@ class ServerCommunicator : public QObject { QString m_email; QString m_password; - // QString m_authToken; + QString m_authToken; }; #endif // SERVERCOMMUNICATOR_H