mobile-widgets: make saveCredentials() an atom

Call saveCredentials with username/password to avoid first
setting the two and then calling.

Change saveCredentials() to use newUser, newPassword.

Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
jan Iversen 2019-12-21 17:33:51 +01:00 committed by Dirk Hohndel
parent e92dbe7974
commit 9117aa2a52
3 changed files with 7 additions and 6 deletions

View file

@ -15,10 +15,8 @@ Item {
property string password: password.text; property string password: password.text;
function saveCredentials() { function saveCredentials() {
prefs.cloudUserName = login.text
prefs.cloudPassword = password.text
prefs.cloudPin = pin.text prefs.cloudPin = pin.text
manager.saveCloudCredentials() manager.saveCloudCredentials(login.text, password.text)
} }
ColumnLayout { ColumnLayout {

View file

@ -458,7 +458,7 @@ void QMLManager::finishSetup()
} else if (!empty_string(existing_filename) && } else if (!empty_string(existing_filename) &&
QMLPrefs::instance()->credentialStatus() != qPrefCloudStorage::CS_UNKNOWN) { QMLPrefs::instance()->credentialStatus() != qPrefCloudStorage::CS_UNKNOWN) {
QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD); QMLPrefs::instance()->setCredentialStatus(qPrefCloudStorage::CS_NOCLOUD);
saveCloudCredentials(); saveCloudCredentials(qPrefCloudStorage::cloud_storage_email(), qPrefCloudStorage::cloud_storage_password());
appendTextToLog(tr("working in no-cloud mode")); appendTextToLog(tr("working in no-cloud mode"));
int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table); int error = parse_file(existing_filename, &dive_table, &trip_table, &dive_site_table);
if (error) { if (error) {
@ -494,11 +494,14 @@ QMLManager *QMLManager::instance()
#define CLOUDURL QString(prefs.cloud_base_url) #define CLOUDURL QString(prefs.cloud_base_url)
#define CLOUDREDIRECTURL CLOUDURL + "/cgi-bin/redirect.pl" #define CLOUDREDIRECTURL CLOUDURL + "/cgi-bin/redirect.pl"
void QMLManager::saveCloudCredentials() void QMLManager::saveCloudCredentials(const QString &newEmail, const QString &newPassword)
{ {
bool cloudCredentialsChanged = false; bool cloudCredentialsChanged = false;
bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD; bool noCloud = QMLPrefs::instance()->credentialStatus() == qPrefCloudStorage::CS_NOCLOUD;
QMLPrefs::instance()->setCloudUserName(newEmail);
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) {

View file

@ -167,7 +167,7 @@ public:
public slots: public slots:
void appInitialized(); void appInitialized();
void applicationStateChanged(Qt::ApplicationState state); void applicationStateChanged(Qt::ApplicationState state);
void saveCloudCredentials(); void saveCloudCredentials(const QString &email, const QString &password);
bool verifyCredentials(QString email, QString password, QString pin); bool verifyCredentials(QString email, QString password, QString pin);
void tryRetrieveDataFromBackend(); void tryRetrieveDataFromBackend();
void handleError(QNetworkReply::NetworkError nError); void handleError(QNetworkReply::NetworkError nError);