Avoid re-entrency in HTTPCredidential::fetch

It is likely to re-enter if there is two jobs that asks for a password.

Example:
 1. log out
 2. restart the application
 3. enter a wrong password
 4. enter a wrong password again a few times
 5. enter the correct password
 6. it should must not prompt for the password again.

Because of the re-entrency, it was still prompting for the password several
times after the right password had been entered
This commit is contained in:
Olivier Goffart 2014-02-26 13:07:42 +01:00
parent 05a1f7b1bb
commit e468ea2d68
2 changed files with 10 additions and 1 deletions

View File

@ -100,7 +100,8 @@ HttpCredentials::HttpCredentials()
HttpCredentials::HttpCredentials(const QString& user, const QString& password)
: _user(user),
_password(password),
_ready(true)
_ready(true),
_fetchJobInProgress(false)
{
}
@ -183,6 +184,10 @@ void HttpCredentials::fetch(Account *account)
return;
}
if (_fetchJobInProgress) {
return;
}
fetchUser(account);
QSettings *settings = account->settingsWithGroup(Theme::instance()->appName());
@ -207,6 +212,7 @@ void HttpCredentials::fetch(Account *account)
connect(job, SIGNAL(finished(QKeychain::Job*)), SLOT(slotReadJobDone(QKeychain::Job*)));
job->setProperty("account", QVariant::fromValue(account));
job->start();
_fetchJobInProgress = true;
}
}
bool HttpCredentials::stillValid(QNetworkReply *reply)
@ -234,6 +240,7 @@ 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 ) {
@ -241,6 +248,7 @@ void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
}
bool ok;
QString pwd = queryPassword(&ok);
_fetchJobInProgress = false;
if (ok) {
_password = pwd;
_ready = true;

View File

@ -62,6 +62,7 @@ private:
QString _user;
QString _password;
bool _ready;
bool _fetchJobInProgress; //True if the keychain job is in progress or the input dialog visible
};
} // ns Mirall