From d717b9d2a70ac778262ba4f525dd7d4972d348cd Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Tue, 10 Sep 2019 11:19:36 +0100 Subject: [PATCH] Mobile: add helper function to check cloud credentials This should do the right thing in the various situations of correct & verified credentials, credentials needing PIN verification, invalid email/password combination, incorrect PIN, correct PIN. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 44 +++++++++++++++++++++++++++++++++++ mobile-widgets/qmlmanager.h | 1 + 2 files changed, 45 insertions(+) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 605525d67..f55cb0caf 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -535,6 +535,50 @@ void QMLManager::saveCloudCredentials() } } +bool QMLManager::verifyCredentials(QString email, QString password, QString pin) +{ + setStartPageText(tr("Testing cloud credentials")); + if (pin.isEmpty()) + appendTextToLog(QStringLiteral("verify credentials for email %1 (no PIN)").arg(email, pin)); + else + appendTextToLog(QStringLiteral("verify credentials for email %1 PIN %2").arg(email, pin)); + CloudStorageAuthenticate *csa = new CloudStorageAuthenticate(this); + csa->backend(email, password, pin); + // 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); + return false; + } + myTimer.stop(); + if (prefs.cloud_verification_status == qPrefCloudStorage::CS_INCORRECT_USER_PASSWD) { + appendTextToLog(QStringLiteral("Incorrect email / password combination")); + setStartPageText(RED_FONT + tr("Incorrect email / password combination") + END_FONT); + return false; + } else if (prefs.cloud_verification_status == qPrefCloudStorage::CS_NEED_TO_VERIFY) { + if (pin.isEmpty()) { + appendTextToLog(QStringLiteral("Cloud credentials require PIN entry")); + setStartPageText(RED_FONT + tr("Cloud credentials require verification PIN") + END_FONT); + } else { + appendTextToLog(QStringLiteral("PIN provided but not accepted")); + setStartPageText(RED_FONT + tr("Incorrect PIN, please try again") + END_FONT); + } + QMLPrefs::instance()->setShowPin(true); + return false; + } else if (prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED) { + appendTextToLog(QStringLiteral("PIN accepted")); + setStartPageText(RED_FONT + tr("PIN accepted, credentials verified") + END_FONT); + } + return true; +} + void QMLManager::tryRetrieveDataFromBackend() { // if the cloud credentials are present, we should try to get the GPS Webservice ID diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index 70fd59f2b..12dbf6f8a 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -148,6 +148,7 @@ public slots: void appInitialized(); void applicationStateChanged(Qt::ApplicationState state); void saveCloudCredentials(); + bool verifyCredentials(QString email, QString password, QString pin); void tryRetrieveDataFromBackend(); void handleError(QNetworkReply::NetworkError nError); void handleSslErrors(const QList &errors);