Use the mirall config file for all Keychain jobs.

Also set the job as parent to get proper deletion of the
settings object.
This commit is contained in:
Klaas Freitag 2014-03-03 16:35:57 +01:00
parent b8e52304bd
commit 1eb0875518

View file

@ -190,10 +190,11 @@ void HttpCredentials::fetch(Account *account)
return;
}
// User must be fetched from config file
fetchUser(account);
QSettings *settings = account->settingsWithGroup(Theme::instance()->appName());
QString kck = keychainKey(account->url().toString(), _user );
const QString kck = keychainKey(account->url().toString(), _user );
QString key = QString::fromLatin1( "%1/data" ).arg( kck );
if( settings && settings->contains(key) ) {
@ -209,8 +210,11 @@ void HttpCredentials::fetch(Account *account)
Q_EMIT fetched();
} else {
ReadPasswordJob *job = new ReadPasswordJob(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
job->setSettings(settings);
job->setInsecureFallback(false);
job->setKey(keychainKey(account->url().toString(), _user));
job->setKey(kck);
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotReadJobDone(QKeychain::Job*)));
job->setProperty("account", QVariant::fromValue(account));
job->start();
@ -227,10 +231,11 @@ bool HttpCredentials::stillValid(QNetworkReply *reply)
void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
{
ReadPasswordJob *readJob = static_cast<ReadPasswordJob*>(job);
delete readJob->settings();
_password = readJob->textData();
Account *account = qvariant_cast<Account*>(readJob->property("account"));
_fetchJobInProgress = false;
if( _user.isEmpty()) {
qDebug() << "Strange: User is empty!";
}
@ -242,7 +247,6 @@ void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
// Still, the password can be empty which indicates a problem and
// the password dialog has to be opened.
_ready = true;
_fetchJobInProgress = false;
emit fetched();
} else {
if( error != NoError ) {
@ -250,7 +254,6 @@ void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
}
bool ok;
QString pwd = queryPassword(&ok);
_fetchJobInProgress = false;
if (ok) {
_password = pwd;
_ready = true;
@ -278,13 +281,26 @@ QString HttpCredentials::queryPassword(bool *ok)
void HttpCredentials::invalidateToken(Account *account)
{
_password = QString();
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
job->setSettings(account->settingsWithGroup(Theme::instance()->appName()));
job->setInsecureFallback(true);
connect(job, SIGNAL(destroyed(QObject*)), job->settings(), SLOT(deleteLater()));
job->setKey(keychainKey(account->url().toString(), _user));
job->start();
_ready = false;
// User must be fetched from config file to generate a valid key
fetchUser(account);
const QString kck = keychainKey(account->url().toString(), _user);
if( kck.isEmpty() ) {
qDebug() << "InvalidateToken: User is empty, bailing out!";
return;
}
DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
QSettings *settings = account->settingsWithGroup(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
job->setSettings(settings);
job->setInsecureFallback(true);
job->setKey(kck);
job->start();
account->clearCookieJar();
}
void HttpCredentials::persist(Account *account)
@ -295,6 +311,10 @@ void HttpCredentials::persist(Account *account)
}
account->setCredentialSetting(QLatin1String(userC), _user);
WritePasswordJob *job = new WritePasswordJob(Theme::instance()->appName());
QSettings *settings = account->settingsWithGroup(Theme::instance()->appName());
settings->setParent(job); // make the job parent to make setting deleted properly
job->setSettings(settings);
job->setInsecureFallback(false);
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotWriteJobDone(QKeychain::Job*)));
job->setKey(keychainKey(account->url().toString(), _user));