From bf15c3977c27536e47578e8b0ecaedb852c5ff52 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 24 Jan 2018 11:25:46 +0100 Subject: Fixed initial account login. Because we ended up trying to load the resources before they even existed (directly after the account was created), we ended up creating a second set of unconfigured resources. Storing the password by modifying the resource was an artifact of the past anyways, and a login function results in a cleaner system and fixes the problem at hand. --- framework/src/domain/settings/accountsettings.cpp | 25 ++++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'framework/src/domain/settings/accountsettings.cpp') diff --git a/framework/src/domain/settings/accountsettings.cpp b/framework/src/domain/settings/accountsettings.cpp index acf85522..a75d5e07 100644 --- a/framework/src/domain/settings/accountsettings.cpp +++ b/framework/src/domain/settings/accountsettings.cpp @@ -56,13 +56,10 @@ void AccountSettings::setAccountIdentifier(const QByteArray &id) mName = QString(); mImapServer = QString(); mImapUsername = QString(); - mImapPassword = QString(); mSmtpServer = QString(); mSmtpUsername = QString(); - mSmtpPassword = QString(); mCardDavServer = QString(); mCardDavUsername = QString(); - mCardDavPassword = QString(); mPath = QString(); emit changed(); emit imapResourceChanged(); @@ -292,9 +289,6 @@ void AccountSettings::saveImapResource() {"server", mImapServer}, {"username", mImapUsername} }); - if (!mImapPassword.isEmpty()) { - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mImapIdentifier, mImapPassword); - } } void AccountSettings::saveCardDavResource() @@ -303,9 +297,6 @@ void AccountSettings::saveCardDavResource() {"server", mCardDavServer}, {"username", mCardDavUsername} }); - if (!mCardDavPassword.isEmpty()) { - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mCardDavIdentifier, mCardDavPassword); - } } void AccountSettings::saveMaildirResource() @@ -321,9 +312,19 @@ void AccountSettings::saveMailtransportResource() {"server", mSmtpServer}, {"username", mSmtpUsername} }); - if (!mSmtpPassword.isEmpty()) { - Kube::AccountKeyring{mAccountIdentifier}.storePassword(mMailtransportIdentifier, mSmtpPassword); - } +} + +void AccountSettings::login(const QVariantMap &secrets) +{ + auto accountSecret = secrets.value("accountSecret").toString(); + Store::fetchAll(Query().filter(mAccountIdentifier)) + .then([=](const QList &resources) { + for (const auto &resource : resources) { + Kube::AccountKeyring{mAccountIdentifier}.storePassword(resource->identifier(), accountSecret); + } + }).onError([](const KAsync::Error &error) { + qWarning() << "Failed to load any account resources resource: " << error; + }).exec(); } void AccountSettings::saveIdentity() -- cgit v1.2.3