prefs: cloud_new_password is not a preference

It's a mamber of the cloud storage authentication class, used to hold the
proposed new password until the backend has accepted it.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2018-09-10 06:49:14 -07:00
parent ae653703a5
commit 2b3f6c607b
9 changed files with 4 additions and 45 deletions

View file

@ -26,6 +26,7 @@ QNetworkReply* CloudStorageAuthenticate::backend(const QString& email,const QStr
} else if (!newpasswd.isEmpty()) {
requestUrl = QUrl(CLOUDBACKENDUPDATE);
payload += QChar(' ') + newpasswd;
cloudNewPassword = newpasswd;
} else {
requestUrl = QUrl(CLOUDBACKENDVERIFY);
payload += QChar(' ') + pin;
@ -64,8 +65,8 @@ void CloudStorageAuthenticate::uploadFinished()
report_error(qPrintable(tr("Cloud account verification required, enter PIN in preferences")));
} else if (cloudAuthReply == QLatin1String("[PASSWDCHANGED]")) {
free((void *)prefs.cloud_storage_password);
prefs.cloud_storage_password = prefs.cloud_storage_newpassword;
prefs.cloud_storage_newpassword = NULL;
prefs.cloud_storage_password = strdup(qPrintable(cloudNewPassword));
cloudNewPassword.clear();
emit passwordChangeSuccessful();
return;
} else {

View file

@ -21,6 +21,7 @@ slots:
private:
QNetworkReply *reply;
QString userAgent;
QString cloudNewPassword;
};
QNetworkAccessManager *manager();

View file

@ -91,7 +91,6 @@ struct preferences {
const char *cloud_git_url;
const char *cloud_storage_email;
const char *cloud_storage_email_encoded;
const char *cloud_storage_newpassword;
const char *cloud_storage_password;
const char *cloud_storage_pin;
short cloud_timeout;

View file

@ -56,17 +56,6 @@ HANDLE_PREFERENCE_TXT(CloudStorage, "email", cloud_storage_email);
HANDLE_PREFERENCE_TXT(CloudStorage, "email_encoded", cloud_storage_email_encoded);
void qPrefCloudStorage::set_cloud_storage_newpassword(const QString &value)
{
if (value == prefs.cloud_storage_newpassword)
return;
qPrefPrivate::copy_txt(&prefs.cloud_storage_newpassword, value);
// NOT saved on disk, because it is only temporary
emit instance()->cloud_storage_newpassword_changed(value);
}
void qPrefCloudStorage::set_cloud_storage_password(const QString &value)
{
if (value != prefs.cloud_storage_password) {

View file

@ -11,7 +11,6 @@ class qPrefCloudStorage : public QObject {
Q_PROPERTY(QString cloud_git_url READ cloud_git_url);
Q_PROPERTY(QString cloud_storage_email READ cloud_storage_email WRITE set_cloud_storage_email NOTIFY cloud_storage_email_changed);
Q_PROPERTY(QString cloud_storage_email_encoded READ cloud_storage_email_encoded WRITE set_cloud_storage_email_encoded NOTIFY cloud_storage_email_encoded_changed);
Q_PROPERTY(QString cloud_storage_newpassword READ cloud_storage_newpassword WRITE set_cloud_storage_newpassword NOTIFY cloud_storage_newpassword_changed);
Q_PROPERTY(QString cloud_storage_password READ cloud_storage_password WRITE set_cloud_storage_password NOTIFY cloud_storage_password_changed);
Q_PROPERTY(QString cloud_storage_pin READ cloud_storage_pin WRITE set_cloud_storage_pin NOTIFY cloud_storage_pin_changed);
Q_PROPERTY(int cloud_verification_status READ cloud_verification_status WRITE set_cloud_verification_status NOTIFY cloud_verification_status_changed);
@ -34,7 +33,6 @@ public:
static QString cloud_git_url() { return prefs.cloud_git_url; }
static QString cloud_storage_email() { return prefs.cloud_storage_email; }
static QString cloud_storage_email_encoded() { return prefs.cloud_storage_email_encoded; }
static QString cloud_storage_newpassword() { return prefs.cloud_storage_newpassword; }
static QString cloud_storage_password() { return prefs.cloud_storage_password; }
static QString cloud_storage_pin() { return prefs.cloud_storage_pin; }
static int cloud_timeout() { return prefs.cloud_timeout; }
@ -47,7 +45,6 @@ public slots:
static void set_cloud_base_url(const QString &value);
static void set_cloud_storage_email(const QString &value);
static void set_cloud_storage_email_encoded(const QString &value);
static void set_cloud_storage_newpassword(const QString &value);
static void set_cloud_storage_password(const QString &value);
static void set_cloud_storage_pin(const QString &value);
static void set_cloud_timeout(int value);
@ -60,7 +57,6 @@ signals:
void cloud_base_url_changed(const QString &value);
void cloud_storage_email_changed(const QString &value);
void cloud_storage_email_encoded_changed(const QString &value);
void cloud_storage_newpassword_changed(const QString &value);
void cloud_storage_password_changed(const QString &value);
void cloud_storage_pin_changed(const QString &value);
void cloud_timeout_changed(int value);
@ -74,7 +70,6 @@ private:
static void disk_cloud_base_url(bool doSync);
static void disk_cloud_storage_email(bool doSync);
static void disk_cloud_storage_email_encoded(bool doSync);
static void disk_cloud_storage_newpassword(bool doSync);
static void disk_cloud_storage_password(bool doSync);
static void disk_cloud_storage_pin(bool doSync);
static void disk_cloud_timeout(bool doSync);

View file

@ -307,7 +307,6 @@ void copy_prefs(struct preferences *src, struct preferences *dest)
dest->date_format = copy_string(src->date_format);
dest->date_format_short = copy_string(src->date_format_short);
dest->cloud_storage_password = copy_string(src->cloud_storage_password);
dest->cloud_storage_newpassword = copy_string(src->cloud_storage_newpassword);
dest->cloud_storage_email = copy_string(src->cloud_storage_email);
dest->cloud_storage_email_encoded = copy_string(src->cloud_storage_email_encoded);
dest->facebook.access_token = copy_string(src->facebook.access_token);

View file

@ -76,7 +76,6 @@ void PreferencesNetwork::syncSettings()
connect(cloudAuth, &CloudStorageAuthenticate::passwordChangeSuccessful, this, &PreferencesNetwork::passwordUpdateSuccessful);
cloudAuth->backend(email, password, "", newpassword);
ui->cloud_storage_new_passwd->setText("");
cloud->set_cloud_storage_newpassword(newpassword);
}
} else if (prefs.cloud_verification_status == qPref::CS_UNKNOWN ||
prefs.cloud_verification_status == qPref::CS_INCORRECT_USER_PASSWD ||

View file

@ -24,7 +24,6 @@ void TestQPrefCloudStorage::test_struct_get()
prefs.cloud_git_url = copy_qstring("new again url");
prefs.cloud_storage_email = copy_qstring("myEmail");
prefs.cloud_storage_email_encoded = copy_qstring("encodedMyEMail");
prefs.cloud_storage_newpassword = copy_qstring("secret");
prefs.cloud_storage_password = copy_qstring("more secret");
prefs.cloud_storage_pin = copy_qstring("a pin");
prefs.cloud_timeout = 117;
@ -37,7 +36,6 @@ void TestQPrefCloudStorage::test_struct_get()
QCOMPARE(tst->cloud_git_url(), QString(prefs.cloud_git_url));
QCOMPARE(tst->cloud_storage_email(), QString(prefs.cloud_storage_email));
QCOMPARE(tst->cloud_storage_email_encoded(), QString(prefs.cloud_storage_email_encoded));
QCOMPARE(tst->cloud_storage_newpassword(), QString(prefs.cloud_storage_newpassword));
QCOMPARE(tst->cloud_storage_password(), QString(prefs.cloud_storage_password));
QCOMPARE(tst->cloud_storage_pin(), QString(prefs.cloud_storage_pin));
QCOMPARE(tst->cloud_timeout(), (int)prefs.cloud_timeout);
@ -56,7 +54,6 @@ void TestQPrefCloudStorage::test_set_struct()
tst->set_cloud_base_url("t2 base");
tst->set_cloud_storage_email("t2 email");
tst->set_cloud_storage_email_encoded("t2 email2");
tst->set_cloud_storage_newpassword("t2 pass1");
tst->set_cloud_storage_password("t2 pass2");
tst->set_cloud_storage_pin("t2 pin");
tst->set_cloud_timeout(123);
@ -68,7 +65,6 @@ void TestQPrefCloudStorage::test_set_struct()
QCOMPARE(QString(prefs.cloud_base_url), QString("t2 base"));
QCOMPARE(QString(prefs.cloud_storage_email), QString("t2 email"));
QCOMPARE(QString(prefs.cloud_storage_email_encoded), QString("t2 email2"));
QCOMPARE(QString(prefs.cloud_storage_newpassword), QString("t2 pass1"));
QCOMPARE(QString(prefs.cloud_storage_password), QString("t2 pass2"));
QCOMPARE(QString(prefs.cloud_storage_pin), QString("t2 pin"));
QCOMPARE((int)prefs.cloud_timeout, 123);
@ -90,7 +86,6 @@ void TestQPrefCloudStorage::test_set_load_struct()
tst->set_cloud_base_url("t3 base");
tst->set_cloud_storage_email("t3 email");
tst->set_cloud_storage_email_encoded("t3 email2");
tst->set_cloud_storage_newpassword("t3 pass1");
tst->set_save_password_local(true);
tst->set_cloud_storage_password("t3 pass2");
tst->set_cloud_storage_pin("t3 pin");
@ -103,7 +98,6 @@ void TestQPrefCloudStorage::test_set_load_struct()
prefs.cloud_git_url = copy_qstring("error1");
prefs.cloud_storage_email = copy_qstring("error1");
prefs.cloud_storage_email_encoded = copy_qstring("error1");
prefs.cloud_storage_newpassword = copy_qstring("my new password");
prefs.cloud_storage_password = copy_qstring("error1");
prefs.cloud_storage_pin = copy_qstring("error1");
prefs.cloud_timeout = 324;
@ -126,9 +120,6 @@ void TestQPrefCloudStorage::test_set_load_struct()
// remark is set with set_base_url
QCOMPARE(QString(prefs.cloud_git_url), QString("t3 base/git"));
// warning new password is not saved on disk
QCOMPARE(QString(prefs.cloud_storage_newpassword), QString("my new password"));
}
void TestQPrefCloudStorage::test_struct_disk()
@ -140,7 +131,6 @@ void TestQPrefCloudStorage::test_struct_disk()
prefs.cloud_base_url = copy_qstring("t4 base");
prefs.cloud_storage_email = copy_qstring("t4 email");
prefs.cloud_storage_email_encoded = copy_qstring("t4 email2");
prefs.cloud_storage_newpassword = copy_qstring("t4 pass1");
prefs.save_password_local = true;
prefs.cloud_storage_password = copy_qstring("t4 pass2");
prefs.cloud_storage_pin = copy_qstring("t4 pin");
@ -155,7 +145,6 @@ void TestQPrefCloudStorage::test_struct_disk()
prefs.cloud_git_url = copy_qstring("error1");
prefs.cloud_storage_email = copy_qstring("error1");
prefs.cloud_storage_email_encoded = copy_qstring("error1");
prefs.cloud_storage_newpassword = copy_qstring("my new password");
prefs.cloud_storage_password = copy_qstring("error1");
prefs.cloud_storage_pin = copy_qstring("error1");
prefs.cloud_timeout = 324;
@ -179,9 +168,6 @@ void TestQPrefCloudStorage::test_struct_disk()
// remark is set with set_base_url
QCOMPARE(QString(prefs.cloud_git_url), QString("t4 base/git"));
// warning new password not stored on disk
QCOMPARE(QString(prefs.cloud_storage_newpassword), QString("my new password"));
}
void TestQPrefCloudStorage::test_multiple()
@ -219,12 +205,6 @@ void TestQPrefCloudStorage::test_oldPreferences()
cloud->set_cloud_storage_email("tomaz@gmail.com");
TEST(cloud->cloud_storage_email(), QStringLiteral("tomaz@gmail.com"));
// Why there's new password and password on the prefs?
cloud->set_cloud_storage_newpassword("ABCD");
TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCD"));
cloud->set_cloud_storage_newpassword("ABCDE");
TEST(cloud->cloud_storage_newpassword(), QStringLiteral("ABCDE"));
cloud->set_cloud_storage_password("ABCDE");
TEST(cloud->cloud_storage_password(), QStringLiteral("ABCDE"));
cloud->set_cloud_storage_password("ABCABC");

View file

@ -30,10 +30,6 @@ TestCase {
tst.cloud_storage_email_encoded= "my email enc"
compare(tst.cloud_storage_email_encoded, "my email enc")
var x5 = tst.cloud_storage_newpassword
tst.cloud_storage_newpassword = "my new password"
compare(tst.cloud_storage_newpassword, "my new password")
var x6 = tst.cloud_storage_password
tst.cloud_storage_password = "my url"
compare(tst.cloud_storage_password, "my url")