diff --git a/src/gui/accountmanager.cpp b/src/gui/accountmanager.cpp index ac804b0fc6d..fdb77b8f87b 100644 --- a/src/gui/accountmanager.cpp +++ b/src/gui/accountmanager.cpp @@ -196,8 +196,8 @@ void AccountManager::saveAccountHelper(Account* acc, QSettings& settings, bool s if (acc->_am) { CookieJar* jar = qobject_cast(acc->_am->cookieJar()); if (jar) { - qDebug() << "Saving cookies."; - jar->save(); + qDebug() << "Saving cookies." << acc->cookieJarPath(); + jar->save(acc->cookieJarPath()); } } } @@ -289,6 +289,8 @@ void AccountManager::deleteAccount(AccountState* account) auto copy = *it; // keep a reference to the shared pointer so it does not delete it just yet _accounts.erase(it); + QFile::remove(account->account()->cookieJarPath()); + auto settings = Utility::settingsWithGroup(QLatin1String(accountsC)); settings->remove(account->account()->id()); diff --git a/src/gui/wizard/owncloudshibbolethcredspage.cpp b/src/gui/wizard/owncloudshibbolethcredspage.cpp index 8fe1706bde8..9b031c064a6 100644 --- a/src/gui/wizard/owncloudshibbolethcredspage.cpp +++ b/src/gui/wizard/owncloudshibbolethcredspage.cpp @@ -44,6 +44,7 @@ void OwncloudShibbolethCredsPage::setupBrowser() // i.e. if someone presses "back" QNetworkAccessManager *qnam = account->networkAccessManager(); CookieJar *jar = new CookieJar; + jar->restore(account->cookieJarPath()); // Implicitly deletes the old cookie jar, and reparents the jar qnam->setCookieJar(jar); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 77f953659a9..203d5557084 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -169,6 +169,12 @@ void Account::lendCookieJarTo(QNetworkAccessManager *guest) jar->setParent(oldParent); // takes it back } +QString Account::cookieJarPath() +{ + ConfigFile cfg; + return cfg.configPath() + "/cookies" + id() + ".db"; +} + void Account::resetNetworkAccessManager() { if (!_credentials || !_am) { diff --git a/src/libsync/account.h b/src/libsync/account.h index 2c21fa548f7..823bfa6d610 100644 --- a/src/libsync/account.h +++ b/src/libsync/account.h @@ -172,6 +172,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject { void clearCookieJar(); void lendCookieJarTo(QNetworkAccessManager *guest); + QString cookieJarPath(); void resetNetworkAccessManager(); QNetworkAccessManager* networkAccessManager(); diff --git a/src/libsync/cookiejar.cpp b/src/libsync/cookiejar.cpp index fd8c5cf995a..b3e20562840 100644 --- a/src/libsync/cookiejar.cpp +++ b/src/libsync/cookiejar.cpp @@ -68,7 +68,6 @@ QDataStream &operator>>(QDataStream &stream, QList &list) CookieJar::CookieJar(QObject *parent) : QNetworkCookieJar(parent) { - restore(); } CookieJar::~CookieJar() @@ -97,21 +96,21 @@ void CookieJar::clearSessionCookies() setAllCookies(removeExpired(allCookies())); } -void CookieJar::save() +void CookieJar::save(const QString &fileName) { QFile file; - file.setFileName(storagePath()); - qDebug() << storagePath(); + file.setFileName(fileName); + qDebug() << fileName; file.open(QIODevice::WriteOnly); QDataStream stream(&file); stream << removeExpired(allCookies()); file.close(); } -void CookieJar::restore() +void CookieJar::restore(const QString &fileName) { QFile file; - file.setFileName(storagePath()); + file.setFileName(fileName); file.open(QIODevice::ReadOnly); QDataStream stream(&file); QList list; @@ -131,10 +130,4 @@ QList CookieJar::removeExpired(const QList &cook return updatedList; } -QString CookieJar::storagePath() const -{ - ConfigFile cfg; - return cfg.configPath() + "/cookies.db"; -} - } // namespace OCC diff --git a/src/libsync/cookiejar.h b/src/libsync/cookiejar.h index 8bc78dc6a2b..9759676b3a7 100644 --- a/src/libsync/cookiejar.h +++ b/src/libsync/cookiejar.h @@ -39,15 +39,13 @@ class OWNCLOUDSYNC_EXPORT CookieJar : public QNetworkCookieJar using QNetworkCookieJar::setAllCookies; using QNetworkCookieJar::allCookies; - void save(); + void save(const QString &fileName); + void restore(const QString &fileName); signals: void newCookiesForUrl(const QList& cookieList, const QUrl& url); private: - void restore(); QList removeExpired(const QList &cookies); - QString storagePath() const; - }; } // namespace OCC