Improve UX for cloud email/password checking

State requirements for email address and
password format within cloud preferences UI

If email address or password entered in cloud
preferences, raise a warning within a
QMessageBox instead of the less-visible
report_error method

Signed-off-by: Jon Massey <jon.massey@thedatalab.org>
This commit is contained in:
Jon Massey 2022-07-18 00:46:15 +01:00 committed by bstoeger
parent 50ff94eb8f
commit 10b4cc9149
2 changed files with 7 additions and 5 deletions

View file

@ -6,6 +6,7 @@
#include "core/errorhelper.h"
#include "core/settings/qPrefCloudStorage.h"
#include <QRegularExpression>
#include <QMessageBox>
PreferencesCloud::PreferencesCloud() : AbstractPreferencesWidget(tr("Cloud"),QIcon(":preferences-cloud-icon"), 9), ui(new Ui::PreferencesCloud())
{
@ -36,6 +37,7 @@ void PreferencesCloud::syncSettings()
QString email = ui->cloud_storage_email->text().toLower();
QString password = ui->cloud_storage_password->text();
QString newpassword = ui->cloud_storage_new_passwd->text();
QString emailpasswordformatwarning = "Change ignored. Cloud storage email and new password can only consist of letters, numbers, and '.', '-', '_', and '+'.";
//TODO: Change this to the Cloud Storage Stuff, not preferences.
if (prefs.cloud_verification_status == qPrefCloudStorage::CS_VERIFIED && !newpassword.isEmpty()) {
@ -44,11 +46,11 @@ void PreferencesCloud::syncSettings()
// 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("Change ignored. Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
QMessageBox::warning(this, tr("Warning"), emailpasswordformatwarning);
return;
}
if (!reg.match(email).hasMatch() || (!newpassword.isEmpty() && !reg.match(newpassword).hasMatch())) {
report_error(qPrintable(tr("Change ignored. Cloud storage email and new password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
QMessageBox::warning(this, tr("Warning"), emailpasswordformatwarning);
ui->cloud_storage_new_passwd->setText("");
return;
}
@ -70,7 +72,7 @@ void PreferencesCloud::syncSettings()
// 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 '+'.")));
QMessageBox::warning(this, tr("Warning"), emailpasswordformatwarning);
cloud->set_cloud_verification_status(oldVerificationStatus);
return;
}
@ -84,7 +86,7 @@ void PreferencesCloud::syncSettings()
// connect to backend server to check / create credentials
QRegularExpression reg("^[a-zA-Z0-9@.+_-]+$");
if (!reg.match(email).hasMatch() || !reg.match(password).hasMatch()) {
report_error(qPrintable(tr("Cloud storage email and password can only consist of letters, numbers, and '.', '-', '_', and '+'.")));
QMessageBox::warning(this, tr("Warning"), emailpasswordformatwarning);
return;
}
CloudStorageAuthenticate *cloudAuth = new CloudStorageAuthenticate(this);

View file

@ -117,7 +117,7 @@
<string extracomment="Help info 1"/>
</property>
<property name="text">
<string>1) Enter an email address and a novel password that Subsurface will use to initialise the dive log in the cloud. Click Apply to send the above email address and password to the (remote) cloud server.</string>
<string>1) Enter an email address and a novel password that Subsurface will use to initialise the dive log in the cloud. Click Apply to send the above email address and password to the (remote) cloud server. Cloud storage email and password can only consist of letters, numbers, and '.','-','_', and '+'.</string>
</property>
</widget>
</item>