QML UI: serialize checking credentials

If we run the backend to verify credentials without waiting for it to
finish, the redirect might happen before we know if the credentials are
invalid, unverified or verified - which will cause us to give the wrong
information to the user.

Yes, this additional wait is annoying, but I can't come up with a better
way to do this and avoid incorrect information. At least the UI isn't hung
while we wait.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-06-13 15:21:51 -07:00
parent f7daadb1cd
commit d2f9803883

View file

@ -9,6 +9,7 @@
#include <QRegularExpression>
#include <QApplication>
#include <QElapsedTimer>
#include <QTimer>
#include "qt-models/divelistmodel.h"
#include "qt-models/gpslistmodel.h"
@ -305,6 +306,34 @@ void QMLManager::checkCredentialsAndExecute(execute_function_type execute)
appendTextToLog("Have credentials, let's see if they are valid");
CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this);
csa->backend(prefs.cloud_storage_email, prefs.cloud_storage_password);
// let's wait here for the signal to avoid too many more nested functions
QTimer myTimer;
myTimer.setSingleShot(true);
QEventLoop loop;
connect(csa, &CloudStorageAuthenticate::finishedAuthenticate, &loop, &QEventLoop::quit);
connect(&myTimer, &QTimer::timeout, &loop, &QEventLoop::quit);
myTimer.start(5000);
loop.exec();
if (!myTimer.isActive()) {
// got no response from the server
setStartPageText(RED_FONT + tr("No response from cloud server to validate the credentials") + END_FONT);
revertToNoCloudIfNeeded();
return;
}
myTimer.stop();
if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
// here we need to enter the PIN
appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN in desktop app"));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
revertToNoCloudIfNeeded();
return;
} else if (prefs.cloud_verification_status != CS_VERIFIED) {
appendTextToLog(QString("Cloud account verification failed - status %1").arg(prefs.cloud_verification_status));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - check developer log") + END_FONT);
revertToNoCloudIfNeeded();
return;
}
// now check the redirect URL to make sure everything is set up on the cloud server
connect(manager(), &QNetworkAccessManager::authenticationRequired, this, &QMLManager::provideAuth, Qt::UniqueConnection);
QUrl url(CLOUDREDIRECTURL);
request = QNetworkRequest(url);
@ -370,18 +399,6 @@ void QMLManager::retrieveUserid()
revertToNoCloudIfNeeded();
return;
}
if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) {
// here we need to enter the PIN
appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN in desktop app"));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + END_FONT);
revertToNoCloudIfNeeded();
return;
} else if (prefs.cloud_verification_status != CS_VERIFIED) {
appendTextToLog(QString("Cloud account verification failed - status %1").arg(prefs.cloud_verification_status));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - check developer log") + END_FONT);
revertToNoCloudIfNeeded();
return;
}
setCredentialStatus(VALID);
QString userid(prefs.userid);
if (userid.isEmpty()) {