diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-07-22 11:10:40 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-22 11:10:40 -0700 |
commit | ce008f52db2359e042dc54d663b5d37fea6f98c3 (patch) | |
tree | 2c41e2f9d73875f8c7f9e879faa89e87bfd9401d | |
parent | 3ba3de8dafcd6478c762f172ec8c54a77a13c7f6 (diff) | |
download | subsurface-ce008f52db2359e042dc54d663b5d37fea6f98c3.tar.gz |
Cloud storage: enable password update
This now allows the user to set a new password for the cloud service.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | qt-ui/preferences.cpp | 30 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.cpp | 8 | ||||
-rw-r--r-- | qt-ui/subsurfacewebservices.h | 2 |
3 files changed, 31 insertions, 9 deletions
diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index 4857e7491..b5fbc601c 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -412,10 +412,28 @@ void PreferencesDialog::syncSettings() s.beginGroup("CloudStorage"); QString email = ui.cloud_storage_email->text(); QString password = ui.cloud_storage_password->text(); - if (prefs.cloud_verification_status == CS_UNKNOWN || - prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || - email != prefs.cloud_storage_email || - password != prefs.cloud_storage_password) { + QString newpassword = ui.cloud_storage_new_passwd->text(); + if (prefs.cloud_verification_status == CS_VERIFIED && !newpassword.isEmpty()) { + // deal with password change + if (!email.isEmpty() && !password.isEmpty()) { + // connect to backend server to check / create credentials + QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$"); + if (!reg.match(email).hasMatch() || (!password.isEmpty() && !reg.match(password).hasMatch())) { + report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'."))); + } else { + CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); + connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); + QNetworkReply *reply = cloudAuth->backend(email, password, "", newpassword); + ui.cloud_storage_new_passwd->setText(""); + ui.cloud_storage_password->setText(newpassword); + password = newpassword; + } + } + } else if (prefs.cloud_verification_status == CS_UNKNOWN || + prefs.cloud_verification_status == CS_INCORRECT_USER_PASSWD || + email != prefs.cloud_storage_email || + password != prefs.cloud_storage_password) { + // different credentials - reset verification status prefs.cloud_verification_status = CS_UNKNOWN; if (!email.isEmpty() && !password.isEmpty()) { @@ -426,7 +444,7 @@ void PreferencesDialog::syncSettings() } else { CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->authenticate(email, password); + QNetworkReply *reply = cloudAuth->backend(email, password); } } } else if (prefs.cloud_verification_status == CS_NEED_TO_VERIFY) { @@ -439,7 +457,7 @@ void PreferencesDialog::syncSettings() } CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this); connect(cloudAuth, SIGNAL(finishedAuthenticate()), this, SLOT(cloudPinNeeded())); - QNetworkReply *reply = cloudAuth->authenticate(email, password, pin); + QNetworkReply *reply = cloudAuth->backend(email, password, pin); } } SAVE_OR_REMOVE("email", default_prefs.cloud_storage_email, email); diff --git a/qt-ui/subsurfacewebservices.cpp b/qt-ui/subsurfacewebservices.cpp index fd9f2fad1..875b8e65c 100644 --- a/qt-ui/subsurfacewebservices.cpp +++ b/qt-ui/subsurfacewebservices.cpp @@ -988,13 +988,17 @@ CloudStorageAuthenticate::CloudStorageAuthenticate(QObject *parent) : #define CLOUDURL QString(prefs.cloud_base_url) #define CLOUDBACKENDSTORAGE CLOUDURL + "/storage" #define CLOUDBACKENDVERIFY CLOUDURL + "/verify" +#define CLOUDBACKENDUPDATE CLOUDURL + "/update" -QNetworkReply* CloudStorageAuthenticate::authenticate(QString email, QString password, QString pin) +QNetworkReply* CloudStorageAuthenticate::backend(QString email, QString password, QString pin, QString newpasswd) { QString payload(email + " " + password); QUrl requestUrl; - if (pin == "") { + if (pin == "" && newpasswd == "") { requestUrl = QUrl(CLOUDBACKENDSTORAGE); + } else if (newpasswd != "") { + requestUrl = QUrl(CLOUDBACKENDUPDATE); + payload += " " + newpasswd; } else { requestUrl = QUrl(CLOUDBACKENDVERIFY); payload += " " + pin; diff --git a/qt-ui/subsurfacewebservices.h b/qt-ui/subsurfacewebservices.h index e4866c529..01aa11713 100644 --- a/qt-ui/subsurfacewebservices.h +++ b/qt-ui/subsurfacewebservices.h @@ -114,7 +114,7 @@ slots: class CloudStorageAuthenticate : public QObject { Q_OBJECT public: - QNetworkReply* authenticate(QString email, QString password, QString pin = ""); + QNetworkReply* backend(QString email, QString password, QString pin = "", QString newpasswd = ""); explicit CloudStorageAuthenticate(QObject *parent); signals: void finishedAuthenticate(); |