mobile UI/login: replace use of cloudPassword

Replace prefs.cloudPassword with PrefCloudStorage.cloud_storage_password in QML

Replace QMLPrefs.....cloudPassword with PrefCloudStorage::cloud_storage_password in C++

Signed-off-by: Jan Iversen <jani@apache.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
jan Iversen 2019-12-20 17:04:28 +01:00 committed by Dirk Hohndel
parent a97cc83458
commit 5af7727ad0
2 changed files with 11 additions and 18 deletions

View file

@ -74,7 +74,7 @@ Item {
Controls.TextField { Controls.TextField {
id: password id: password
text: prefs.cloudPassword text: PrefCloudStorage.cloud_storage_password
visible: !rootItem.showPin visible: !rootItem.showPin
echoMode: TextInput.PasswordEchoOnEdit echoMode: TextInput.PasswordEchoOnEdit
inputMethodHints: Qt.ImhSensitiveData | inputMethodHints: Qt.ImhSensitiveData |

View file

@ -442,13 +442,12 @@ QString QMLManager::getCombinedLogs()
void QMLManager::finishSetup() void QMLManager::finishSetup()
{ {
// Initialize cloud credentials. // Initialize cloud credentials.
QMLPrefs::instance()->setCloudPassword(qPrefCloudStorage::cloud_storage_password());
git_local_only = !prefs.cloud_auto_sync; git_local_only = !prefs.cloud_auto_sync;
QMLPrefs::instance()->setCredentialStatus((qPrefCloudStorage::cloud_status) prefs.cloud_verification_status); QMLPrefs::instance()->setCredentialStatus((qPrefCloudStorage::cloud_status) prefs.cloud_verification_status);
// if the cloud credentials are valid, we should get the GPS Webservice ID as well // if the cloud credentials are valid, we should get the GPS Webservice ID as well
QString url; QString url;
if (!qPrefCloudStorage::cloud_storage_email().isEmpty() && if (!qPrefCloudStorage::cloud_storage_email().isEmpty() &&
!QMLPrefs::instance()->cloudPassword().isEmpty() && !qPrefCloudStorage::cloud_storage_password().isEmpty() &&
getCloudURL(url) == 0) { getCloudURL(url) == 0) {
// we know that we are the first ones to access git storage, so we don't need to test, // we know that we are the first ones to access git storage, so we don't need to test,
// but we need to make sure we stay the only ones accessing git storage // but we need to make sure we stay the only ones accessing git storage
@ -498,14 +497,12 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
bool cloudCredentialsChanged = false; bool cloudCredentialsChanged = false;
bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD; bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD;
QMLPrefs::instance()->setCloudPassword(newPassword);
// make sure we only have letters, numbers, and +-_. in password and email address // make sure we only have letters, numbers, and +-_. in password and email address
QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$"); QRegularExpression regExp("^[a-zA-Z0-9@.+_-]+$");
if (!noCloud) { if (!noCloud) {
// in case of NO_CLOUD, the email address + passwd do not care, so do not check it. // in case of NO_CLOUD, the email address + passwd do not care, so do not check it.
if (QMLPrefs::instance()->cloudPassword().isEmpty() || if (newPassword.isEmpty() ||
!regExp.match(QMLPrefs::instance()->cloudPassword()).hasMatch() || !regExp.match(newPassword).hasMatch() ||
!regExp.match(newEmail).hasMatch()) { !regExp.match(newEmail).hasMatch()) {
setStartPageText(RED_FONT + tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.") + END_FONT); setStartPageText(RED_FONT + tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.") + END_FONT);
return; return;
@ -521,8 +518,9 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
cloudCredentialsChanged = true; cloudCredentialsChanged = true;
} }
cloudCredentialsChanged |= !same_string(prefs.cloud_storage_password, if (!same_string(prefs.cloud_storage_password, qPrintable(newPassword))) {
qPrintable(QMLPrefs::instance()->cloudPassword())); cloudCredentialsChanged = true;
}
if (QMLPrefs::instance()->credentialStatus() != qPrefCloudStorage::CS_NOCLOUD && if (QMLPrefs::instance()->credentialStatus() != qPrefCloudStorage::CS_NOCLOUD &&
!cloudCredentialsChanged) { !cloudCredentialsChanged) {
@ -531,18 +529,13 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
} }
if (!noCloud && if (!noCloud &&
!verifyCredentials(newEmail, QMLPrefs::instance()->cloudPassword(), QMLPrefs::instance()->cloudPin())) !verifyCredentials(newEmail, newPassword, QMLPrefs::instance()->cloudPin()))
return; return;
qPrefCloudStorage::set_cloud_storage_email(newEmail); qPrefCloudStorage::set_cloud_storage_email(newEmail);
qPrefCloudStorage::set_cloud_storage_password(QMLPrefs::instance()->cloudPassword()); qPrefCloudStorage::set_cloud_storage_password(newPassword);
qPrefCloudStorage::set_cloud_verification_status(QMLPrefs::instance()->credentialStatus()); qPrefCloudStorage::set_cloud_verification_status(QMLPrefs::instance()->credentialStatus());
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 (noCloud && cloudCredentialsChanged && dive_table.nr) { if (noCloud && cloudCredentialsChanged && dive_table.nr) {
// we came from NOCLOUD and are connecting to a cloud account; // 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 // since we already have dives in the table, let's remember that so we can keep them
@ -550,7 +543,7 @@ void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &ne
appendTextToLog("transitioning from no-cloud to cloud and have dives"); appendTextToLog("transitioning from no-cloud to cloud and have dives");
} }
if (qPrefCloudStorage::cloud_storage_email().isEmpty() || if (qPrefCloudStorage::cloud_storage_email().isEmpty() ||
QMLPrefs::instance()->cloudPassword().isEmpty()) { qPrefCloudStorage::cloud_storage_password().isEmpty()) {
setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT); setStartPageText(RED_FONT + tr("Please enter valid cloud credentials.") + END_FONT);
} else if (cloudCredentialsChanged) { } else if (cloudCredentialsChanged) {
// let's make sure there are no unsaved changes // let's make sure there are no unsaved changes
@ -828,7 +821,7 @@ void QMLManager::revertToNoCloudIfNeeded()
free((void *)prefs.cloud_storage_password); free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = NULL; prefs.cloud_storage_password = NULL;
qPrefCloudStorage::set_cloud_storage_email(""); qPrefCloudStorage::set_cloud_storage_email("");
QMLPrefs::instance()->setCloudPassword(""); qPrefCloudStorage::set_cloud_storage_password("");
QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD);
set_filename(NOCLOUD_LOCALSTORAGE); set_filename(NOCLOUD_LOCALSTORAGE);
setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT); setStartPageText(RED_FONT + tr("Failed to connect to cloud server, reverting to no cloud status") + END_FONT);