summaryrefslogtreecommitdiffstats
path: root/mobile-widgets/qmlmanager.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2019-09-10 11:24:06 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-09-11 21:50:41 +0100
commitf6f6a2055579808430a2f843b003397242bdecbd (patch)
tree7733ef09053a57a96dd0232d0a8dea97ea59e244 /mobile-widgets/qmlmanager.cpp
parentd717b9d2a70ac778262ba4f525dd7d4972d348cd (diff)
downloadsubsurface-f6f6a2055579808430a2f843b003397242bdecbd.tar.gz
Mobile: check if credentials are valid before accepting them
It seems crazy to simply assume that the later code can successfully untangle the various states that the credentials can be in - let's just stay on the credentials enrty page until we have verified credentials. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets/qmlmanager.cpp')
-rw-r--r--mobile-widgets/qmlmanager.cpp21
1 files changed, 14 insertions, 7 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index f55cb0caf..ea0f52c6c 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -457,9 +457,11 @@ void QMLManager::saveCloudCredentials()
{
QSettings s;
bool cloudCredentialsChanged = false;
+ bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD;
+
// make sure we only have letters, numbers, and +-_. in password and email address
QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$");
- if (QMLPrefs::instance()->credentialStatus() != qPrefCloudStorage::CS_NOCLOUD) {
+ if (!noCloud) {
// in case of NO_CLOUD, the email address + passwd do not care, so do not check it.
if (QMLPrefs::instance()->cloudPassword().isEmpty() ||
!regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() ||
@@ -474,11 +476,6 @@ void QMLManager::saveCloudCredentials()
return;
}
}
- s.beginGroup("CloudStorage");
- s.setValue("email", QMLPrefs::instance()->cloudUserName());
- s.setValue("password", QMLPrefs::instance()->cloudPassword());
- s.setValue("cloud_verification_status", QMLPrefs::instance()->credentialStatus());
- s.sync();
if (!same_string(prefs.cloud_storage_email,
qPrintable(QMLPrefs::instance()->cloudUserName()))) {
free((void *)prefs.cloud_storage_email);
@@ -495,12 +492,22 @@ void QMLManager::saveCloudCredentials()
QMLPrefs::instance()->setCredentialStatus(QMLPrefs::instance()->oldStatus());
}
+ if (!noCloud &&
+ !verifyCredentials(QMLPrefs::instance()->cloudUserName(), QMLPrefs::instance()->cloudPassword(), QMLPrefs::instance()->cloudPin()))
+ return;
+
+ s.beginGroup("CloudStorage");
+ s.setValue("email", QMLPrefs::instance()->cloudUserName());
+ s.setValue("password", QMLPrefs::instance()->cloudPassword());
+ s.setValue("cloud_verification_status", QMLPrefs::instance()->credentialStatus());
+ s.sync();
+
if (!same_string(prefs.cloud_storage_password,
qPrintable(QMLPrefs::instance()->cloudPassword()))) {
free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = copy_qstring(QMLPrefs::instance()->cloudPassword());
}
- if (QMLPrefs::instance()->oldStatus() == qPrefCloudStorage::CS_NOCLOUD && cloudCredentialsChanged && dive_table.nr) {
+ if (noCloud && cloudCredentialsChanged && dive_table.nr) {
// we came from NOCLOUD and are connecting to a cloud account;
// since we already have dives in the table, let's remember that so we can keep them
noCloudToCloud = true;