Skip to content

Commit 2436f79

Browse files
committed
prevent nextcloud connector's attempt to read a password when no username has been set
1 parent eb4e3ae commit 2436f79

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/common/settings/settingsmanager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,17 @@ auto SettingsManager::getPassword(const QString &username, const QString &servic
133133

134134
if (job->error())
135135
{
136-
qCCritical(gmSettings) << "Could not read password:" << job->error() << job->errorString();
136+
if (username.isEmpty())
137+
{
138+
qCCritical(gmSettings) << "Could not read password for service" << service
139+
<< "(no username):" << job->error() << job->errorString();
140+
}
141+
else
142+
{
143+
qCCritical(gmSettings) << "Could not read password for service" << service << ":" << job->error()
144+
<< job->errorString();
145+
}
146+
137147
return u""_s;
138148
}
139149

src/services/nextcloud/nextcloudconnector.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,23 @@ NextCloudConnector::NextCloudConnector(NextCloud *nc, QObject *parent)
3232
connect(this, &NextCloudConnector::stateChanged, this, &NextCloudConnector::onStateChanged);
3333
state(State::Connecting);
3434

35-
QTimer::singleShot(0, this, [this]() {
36-
m_appPassword = SettingsManager::getPassword(m_nc->loginName(), m_nc->serviceName());
37-
38-
if (m_nc->loginName().isEmpty() || m_appPassword.isEmpty() || m_nc->serverUrl().isEmpty())
39-
{
40-
state(State::Disconnected);
41-
}
42-
else
43-
{
44-
qCDebug(gmNcConnector()) << "Connected to Nextcloud as user" << m_nc->loginName() << "on server"
45-
<< m_nc->serverUrl();
46-
state(State::Connected);
47-
}
48-
});
35+
if (!m_nc->loginName().isEmpty())
36+
{
37+
QTimer::singleShot(0, this, [this]() {
38+
m_appPassword = SettingsManager::getPassword(m_nc->loginName(), m_nc->serviceName());
39+
40+
if (m_nc->loginName().isEmpty() || m_appPassword.isEmpty() || m_nc->serverUrl().isEmpty())
41+
{
42+
state(State::Disconnected);
43+
}
44+
else
45+
{
46+
qCDebug(gmNcConnector()) << "Connected to Nextcloud as user" << m_nc->loginName() << "on server"
47+
<< m_nc->serverUrl();
48+
state(State::Connected);
49+
}
50+
});
51+
}
4952
}
5053

5154
void NextCloudConnector::grantAccess()

0 commit comments

Comments
 (0)