diff --git a/src/bugzillaintegration/bugzillalib.h b/src/bugzillaintegration/bugzillalib.h --- a/src/bugzillaintegration/bugzillalib.h +++ b/src/bugzillaintegration/bugzillalib.h @@ -44,6 +44,7 @@ /* Login methods */ void tryLogin(const QString &username, const QString &password); + void refreshToken(); bool getLogged() const; QString getUsername() const; diff --git a/src/bugzillaintegration/bugzillalib.cpp b/src/bugzillaintegration/bugzillalib.cpp --- a/src/bugzillaintegration/bugzillalib.cpp +++ b/src/bugzillaintegration/bugzillalib.cpp @@ -159,21 +159,33 @@ { m_username = username; m_password = password; + refreshToken(); +} + +void BugzillaManager::refreshToken() +{ + Q_ASSERT(!m_username.isEmpty()); + Q_ASSERT(!m_password.isEmpty()); m_logged = false; + // Rest token and qdebug filters + Bugzilla::connection().setToken(QString()); s_messageFilter->clear(); - s_messageFilter->insert(password, QStringLiteral("PASSWORD")); - KJob *job = Bugzilla::login(username, password); + s_messageFilter->insert(m_password, QStringLiteral("PASSWORD")); + + KJob *job = Bugzilla::login(m_username, m_password); connect(job, &KJob::finished, this, [this](KJob *job) { try { auto details = Bugzilla::login(job); m_token = details.token; if (m_token.isEmpty()) { throw Bugzilla::RuntimeException(QStringLiteral("Did not receive a token")); } + s_messageFilter->insert(m_token, QStringLiteral("TOKEN")); Bugzilla::connection().setToken(m_token); m_logged = true; + emit loginFinished(true); } catch (Bugzilla::Exception &e) { qCWarning(DRKONQI_LOG) << e.whatString(); diff --git a/src/bugzillaintegration/reportassistantpages_bugzilla.cpp b/src/bugzillaintegration/reportassistantpages_bugzilla.cpp --- a/src/bugzillaintegration/reportassistantpages_bugzilla.cpp +++ b/src/bugzillaintegration/reportassistantpages_bugzilla.cpp @@ -665,11 +665,32 @@ void BugzillaSendPage::aboutToShow() { ui.m_statusWidget->setBusy(i18nc("@info:status","Sending crash report... (please wait)")); - reportInterface()->sendBugReport(); + + // Trigger relogin. If the user took a long time to prepare the login our + // token might have gone invalid in the meantime. As a cheap way to prevent + // this we'll simply refresh the token regardless. It's plenty cheap and + // should reliably ensure that the token is current. + // Disconnect everything first though, this function may get called a bunch + // of times, so we don't want duplicated submissions. + disconnect(bugzillaManager(), &BugzillaManager::loginFinished, + reportInterface(), &ReportInterface::sendBugReport); + disconnect(bugzillaManager(), &BugzillaManager::loginError, + this, nullptr); + connect(bugzillaManager(), &BugzillaManager::loginFinished, + reportInterface(), &ReportInterface::sendBugReport); + connect(bugzillaManager(), &BugzillaManager::loginError, + this, [this](const QString &error) { sendError(error, QString()); }); + bugzillaManager()->refreshToken(); } void BugzillaSendPage::sent(int bug_id) { + // Disconnect login->submit chain again. + disconnect(bugzillaManager(), &BugzillaManager::loginFinished, + reportInterface(), &ReportInterface::sendBugReport); + disconnect(bugzillaManager(), &BugzillaManager::loginError, + this, nullptr); + ui.m_statusWidget->setVisible(false); ui.m_retryButton->setEnabled(false); ui.m_retryButton->setVisible(false); diff --git a/src/bugzillaintegration/reportinterface.h b/src/bugzillaintegration/reportinterface.h --- a/src/bugzillaintegration/reportinterface.h +++ b/src/bugzillaintegration/reportinterface.h @@ -61,7 +61,6 @@ QString generateReportFullText(bool drKonqiStamp) const; Bugzilla::NewBug newBugReportTemplate() const; - void sendBugReport() const; QStringList relatedBugzillaProducts() const; @@ -92,6 +91,9 @@ return m_provideApplicationConfigurationDetails; } +public Q_SLOTS: + void sendBugReport() const; + private Q_SLOTS: void sendUsingDefaultProduct() const; void addedToCC();