Skip to content

Commit

Permalink
prevent nextcloud connector's attempt to read a password when no user…
Browse files Browse the repository at this point in the history
…name has been set
  • Loading branch information
PhilInTheGaps committed Jan 5, 2025
1 parent eb4e3ae commit 2436f79
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
12 changes: 11 additions & 1 deletion src/common/settings/settingsmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,17 @@ auto SettingsManager::getPassword(const QString &username, const QString &servic

if (job->error())
{
qCCritical(gmSettings) << "Could not read password:" << job->error() << job->errorString();
if (username.isEmpty())
{
qCCritical(gmSettings) << "Could not read password for service" << service
<< "(no username):" << job->error() << job->errorString();
}
else
{
qCCritical(gmSettings) << "Could not read password for service" << service << ":" << job->error()
<< job->errorString();
}

return u""_s;
}

Expand Down
31 changes: 17 additions & 14 deletions src/services/nextcloud/nextcloudconnector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ NextCloudConnector::NextCloudConnector(NextCloud *nc, QObject *parent)
connect(this, &NextCloudConnector::stateChanged, this, &NextCloudConnector::onStateChanged);
state(State::Connecting);

QTimer::singleShot(0, this, [this]() {
m_appPassword = SettingsManager::getPassword(m_nc->loginName(), m_nc->serviceName());

if (m_nc->loginName().isEmpty() || m_appPassword.isEmpty() || m_nc->serverUrl().isEmpty())
{
state(State::Disconnected);
}
else
{
qCDebug(gmNcConnector()) << "Connected to Nextcloud as user" << m_nc->loginName() << "on server"
<< m_nc->serverUrl();
state(State::Connected);
}
});
if (!m_nc->loginName().isEmpty())
{
QTimer::singleShot(0, this, [this]() {
m_appPassword = SettingsManager::getPassword(m_nc->loginName(), m_nc->serviceName());

if (m_nc->loginName().isEmpty() || m_appPassword.isEmpty() || m_nc->serverUrl().isEmpty())
{
state(State::Disconnected);
}
else
{
qCDebug(gmNcConnector()) << "Connected to Nextcloud as user" << m_nc->loginName() << "on server"
<< m_nc->serverUrl();
state(State::Connected);
}
});
}
}

void NextCloudConnector::grantAccess()
Expand Down

0 comments on commit 2436f79

Please sign in to comment.