Skip to content

Commit

Permalink
HIBP: Display error message in table if download from HIBP failed
Browse files Browse the repository at this point in the history
  • Loading branch information
wolframroesler committed Mar 14, 2020
1 parent 1802f66 commit 9909334
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/core/HibpDownloader.cpp
Expand Up @@ -137,6 +137,7 @@ void HibpDownloader::fetchReadyRead()
void HibpDownloader::fetchFinished()
{
const auto ok = m_reply->error() == QNetworkReply::NoError;
const auto err = m_reply->errorString();

m_reply->deleteLater();
m_reply = nullptr;
Expand All @@ -145,8 +146,10 @@ void HibpDownloader::fetchFinished()
if (ok) {
emit finished(m_password, pwnCount(m_password, m_bytesReceived));
} else {

// TODO: Get the error message
emit failed(m_password, "Error message goes here");
auto msg = tr("Online password validation failed") + ":\n" + err;
if (!m_bytesReceived.isEmpty()) {
msg += "\n" + m_bytesReceived;
}
emit failed(m_password, msg);
}
}
23 changes: 21 additions & 2 deletions src/gui/reports/ReportsWidgetHibp.cpp
Expand Up @@ -50,6 +50,7 @@ void ReportsWidgetHibp::loadSettings(QSharedPointer<Database> db)
m_referencesModel->clear();
m_pwQueue.clear();
m_pwPwned.clear();
m_error.clear();
m_rowToEntry.clear();
m_edEntry = nullptr;
m_ui->progressBar->hide();
Expand Down Expand Up @@ -112,6 +113,14 @@ void ReportsWidgetHibp::makeHibpTable() {
}
}

// If there was an error, append the error message to the table
if (!m_error.isEmpty()) {
auto row = QList<QStandardItem*>();
row << new QStandardItem(m_error);
m_referencesModel->appendRow(row);
row[0]->setForeground(QBrush(QColor("red")));
}

m_ui->hibpTableView->resizeRowsToContents();
}

Expand Down Expand Up @@ -139,10 +148,16 @@ void ReportsWidgetHibp::checkFinished(const QString& password, int count)

/*
* Invoked when a query to the HIBP server fails.
*
* Displays the table with the current findings and quits the online activity.
*/
void ReportsWidgetHibp::checkFailed(const QString& password, const QString& error)
void ReportsWidgetHibp::checkFailed(const QString& /*password*/, const QString& error)
{
// TODO: Display the error message
m_error = error;
m_pwQueue.clear();
m_downloader.reset();
m_ui->progressBar->hide();
makeHibpTable();
}

/*
Expand Down Expand Up @@ -173,6 +188,10 @@ void ReportsWidgetHibp::checkNext()
SIGNAL(finished(const QString&, int)),
this,
SLOT(checkFinished(const QString&, int)));
connect(&*m_downloader,
SIGNAL(failed(const QString&, const QString&)),
this,
SLOT(checkFailed(const QString&, const QString&)));
}

void ReportsWidgetHibp::showEvent(QShowEvent* event)
Expand Down
1 change: 1 addition & 0 deletions src/gui/reports/ReportsWidgetHibp.h
Expand Up @@ -70,6 +70,7 @@ public slots:
int m_qMax = 0; // Max number of items in the queue (for progress bar)
QSet<QString> m_pwQueue; // Passwords we still need to check
QMap<QString, int> m_pwPwned; // Passwords we found to have been pwned (value is pwn count)
QString m_error; // Error message if download failed, else empty
QList<QPair<const Group*, const Entry*>> m_rowToEntry; // List index is table row
const Entry *m_edEntry = nullptr; // The entry we're currently editing
QString m_edPw; // The old password of the entry we're editing
Expand Down

0 comments on commit 9909334

Please sign in to comment.