mobile/cleanup: remove the second access to cloud data

While I remember some of the thinking that went into doing things this way,
the more I read the code, the less it makes sense to me.

This is a rather drastic step, but in reasonably extensive testing it seems
to work in every case that I tried.

That's rather embarrassing, actually.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-17 09:07:11 -07:00
parent 4bd217299a
commit 8e7711c054
2 changed files with 0 additions and 117 deletions

View file

@ -388,9 +388,6 @@ void QMLManager::openLocalThenRemote(QString url)
if (qPrefCloudStorage::cloud_verification_status() != qPrefCloudStorage::CS_NOCLOUD) if (qPrefCloudStorage::cloud_verification_status() != qPrefCloudStorage::CS_NOCLOUD)
appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network")); appendTextToLog(QStringLiteral("have cloud credentials, but user asked not to connect to network"));
alreadySaving = false; alreadySaving = false;
} else {
appendTextToLog(QStringLiteral("have cloud credentials, trying to connect"));
tryRetrieveDataFromBackend();
} }
updateAllGlobalLists(); updateAllGlobalLists();
} }
@ -667,115 +664,6 @@ bool QMLManager::verifyCredentials(QString email, QString password, QString pin)
return true; return true;
} }
void QMLManager::tryRetrieveDataFromBackend()
{
// if the cloud credentials are present, we should try to get the GPS Webservice ID
// and (if we haven't done so) load the dive list
if (!empty_string(prefs.cloud_storage_email) &&
!empty_string(prefs.cloud_storage_password)) {
setStartPageText(tr("Testing cloud credentials"));
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 == qPrefCloudStorage::CS_INCORRECT_USER_PASSWD) {
appendTextToLog(QStringLiteral("Incorrect cloud credentials"));
setStartPageText(RED_FONT + tr("Incorrect cloud credentials") + END_FONT);
revertToNoCloudIfNeeded();
return;
} else if (prefs.cloud_verification_status != qPrefCloudStorage::CS_VERIFIED) {
// here we need to enter the PIN
appendTextToLog(QStringLiteral("Need to verify the email address - enter PIN"));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage - cloud account not verified") + 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);
QNetworkRequest request(url);
request.setRawHeader("User-Agent", getUserAgent().toUtf8());
request.setRawHeader("Accept", "text/html");
QNetworkReply *reply = manager()->get(request);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(handleError(QNetworkReply::NetworkError)));
connect(reply, &QNetworkReply::sslErrors, this, &QMLManager::handleSslErrors);
connect(reply, &QNetworkReply::finished, this, &QMLManager::retrieveUserid);
}
}
void QMLManager::provideAuth(QNetworkReply *reply, QAuthenticator *auth)
{
if (auth->user() == QString(prefs.cloud_storage_email) &&
auth->password() == QString(prefs.cloud_storage_password)) {
// OK, credentials have been tried and didn't work, so they are invalid
appendTextToLog("Cloud credentials are invalid");
setStartPageText(RED_FONT + tr("Cloud credentials are invalid") + END_FONT);
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_INCORRECT_USER_PASSWD);
reply->disconnect();
reply->abort();
reply->deleteLater();
return;
}
auth->setUser(prefs.cloud_storage_email);
auth->setPassword(prefs.cloud_storage_password);
}
void QMLManager::handleSslErrors(const QList<QSslError> &errors)
{
auto *reply = qobject_cast<QNetworkReply *>(sender());
setStartPageText(RED_FONT + tr("Cannot open cloud storage: Error creating https connection") + END_FONT);
for (QSslError e: errors) {
appendTextToLog(e.errorString());
}
reply->abort();
reply->deleteLater();
setNotificationText(QStringLiteral(""));
}
void QMLManager::handleError(QNetworkReply::NetworkError nError)
{
auto *reply = qobject_cast<QNetworkReply *>(sender());
QString errorString = reply->errorString();
appendTextToLog(QStringLiteral("handleError ") + nError + QStringLiteral(": ") + errorString);
setStartPageText(RED_FONT + tr("Cannot open cloud storage: %1").arg(errorString) + END_FONT);
reply->abort();
reply->deleteLater();
setNotificationText(QStringLiteral(""));
}
void QMLManager::retrieveUserid()
{
auto *reply = qobject_cast<QNetworkReply *>(sender());
if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute) != 302) {
appendTextToLog(QStringLiteral("Cloud storage connection not working correctly: (%1) %2")
.arg(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt())
.arg(QString(reply->readAll())));
setStartPageText(RED_FONT + tr("Cannot connect to cloud storage") + END_FONT);
revertToNoCloudIfNeeded();
return;
}
qPrefCloudStorage::set_cloud_verification_status(qPrefCloudStorage::CS_VERIFIED);
setStartPageText(tr("Cloud credentials valid, loading dives..."));
// this only gets called with "alreadySaving" already locked
loadDivesWithValidCredentials();
}
void QMLManager::loadDivesWithValidCredentials() void QMLManager::loadDivesWithValidCredentials()
{ {
QString url; QString url;

View file

@ -170,12 +170,7 @@ public slots:
void appInitialized(); void appInitialized();
void applicationStateChanged(Qt::ApplicationState state); void applicationStateChanged(Qt::ApplicationState state);
void saveCloudCredentials(const QString &email, const QString &password, const QString &pin); void saveCloudCredentials(const QString &email, const QString &password, const QString &pin);
void tryRetrieveDataFromBackend();
void handleError(QNetworkReply::NetworkError nError);
void handleSslErrors(const QList<QSslError> &errors);
void retrieveUserid();
void loadDivesWithValidCredentials(); void loadDivesWithValidCredentials();
void provideAuth(QNetworkReply *reply, QAuthenticator *auth);
void commitChanges(QString diveId, QString number, QString date, QString location, QString gps, void commitChanges(QString diveId, QString number, QString date, QString location, QString gps,
QString duration, QString depth, QString airtemp, QString duration, QString depth, QString airtemp,
QString watertemp, QString suit, QString buddy, QString watertemp, QString suit, QString buddy,