if (auto accState = AccountState::loadFromSettings(acc, *settings)) {
auto jar = qobject_cast<CookieJar*>(acc->_am->cookieJar());
ASSERT(jar);
- if (jar)
+ if (jar) {
jar->restore(acc->cookieJarPath());
+ }
addAccountState(accState);
}
}
void AccountManager::saveAccountHelper(Account *acc, QSettings &settings, bool saveCredentials)
{
+ qCDebug(lcAccountManager) << "Saving settings to" << settings.fileName();
settings.setValue(QLatin1String(versionC), maxAccountVersion);
settings.setValue(QLatin1String(urlC), acc->_url.toString());
settings.setValue(QLatin1String(davUserC), acc->_davUser);
settings.setValue(QLatin1String(authTypeC), acc->_credentials->authType());
// HACK: Save http_user also as user
- if (acc->_settingsMap.contains(httpUserC))
+ if (acc->_settingsMap.contains(httpUserC)) {
settings.setValue(userC, acc->_settingsMap.value(httpUserC));
+ }
}
// Save accepted certificates.
auto authType = settings.value(QLatin1String(authTypeC)).toString();
// There was an account-type saving bug when 'skip folder config' was used
- // See #5408. This attempts to fix up the "dummy" authType
- if (authType == QLatin1String(dummyAuthTypeC)) {
+ // See owncloud#5408. This attempts to fix up the "dummy" or empty authType
+ if (authType == QLatin1String(dummyAuthTypeC) || authType.isEmpty()) {
if (settings.contains(QLatin1String(httpUserC))) {
authType = httpAuthTypeC;
} else if (settings.contains(QLatin1String(shibbolethUserC))) {
// Migrate to webflow
if (authType == QLatin1String(httpAuthTypeC)) {
authType = webflowAuthTypeC;
- settings.setValue(QLatin1String(authTypeC), authType);
+ acc->_settingsMap.insert(QLatin1String(authTypeC), authType);
const auto settingsChildKeys = settings.childKeys();
for (const auto &key : settingsChildKeys) {
- if (!key.startsWith(httpAuthPrefix))
+ if (!key.startsWith(httpAuthPrefix)) {
continue;
+ }
+
const auto newkey = QString::fromLatin1(webflowAuthPrefix).append(key.mid(5));
- settings.setValue(newkey, settings.value((key)));
- settings.remove(key);
+ acc->_settingsMap.insert(newkey, settings.value(key));
}
}
acc->_serverColor = settings.value(QLatin1String(serverColorC)).value<QColor>();
acc->_serverTextColor = settings.value(QLatin1String(serverTextColorC)).value<QColor>();
acc->_skipE2eeMetadataChecksumValidation = settings.value(QLatin1String(skipE2eeMetadataChecksumValidationC), {}).toBool();
- acc->_davUser = settings.value(QLatin1String(davUserC), "").toString();
+ acc->_davUser = settings.value(QLatin1String(davUserC)).toString();
- // We want to only restore settings for that auth type and the user value
acc->_settingsMap.insert(QLatin1String(userC), settings.value(userC));
acc->_displayName = settings.value(QLatin1String(displayNameC), "").toString();
- QString authTypePrefix = authType + "_";
+ const QString authTypePrefix = authType + "_";
const auto settingsChildKeys = settings.childKeys();
for (const auto &key : settingsChildKeys) {
- if (!key.startsWith(authTypePrefix))
+ if (!key.startsWith(authTypePrefix)) {
continue;
+ }
acc->_settingsMap.insert(key, settings.value(key));
}
void WebFlowCredentials::slotAskFromUserCredentialsProvided(const QString &user, const QString &pass, const QString &host) {
Q_UNUSED(host)
- // Compare the re-entered username case-insensitive and save the new value (avoid breaking the account)
- // See issue: https://github.com/nextcloud/desktop/issues/1741
- if (QString::compare(_user, user, Qt::CaseInsensitive) == 0) {
- _user = user;
- } else {
- qCInfo(lcWebFlowCredentials()) << "Authed with the wrong user!";
-
- QString msg = tr("Please login with the account: %1")
- .arg(_account->prettyName());
- _askDialog->setError(msg);
-
- if (!_askDialog->isUsingFlow2()) {
- QUrl url = _account->url();
- QString path = url.path() + "/index.php/login/flow";
- url.setPath(path);
- _askDialog->setUrl(url);
- }
-
- return;
- }
-
qCInfo(lcWebFlowCredentials()) << "Obtained a new password";
+ _user = user;
_password = pass;
_ready = true;
_credentialsValid = true;
AccountPtr account = _accountState->account();
- // User Info
- QString user = objData.value("id").toString();
- if (!user.isEmpty()) {
- account->setDavUser(user);
+ if (const auto newUserId = objData.value("id").toString();!newUserId.isEmpty()) {
+ if (QString::compare(account->davUser(), newUserId, Qt::CaseInsensitive) != 0) {
+ // TODO: the error message should be in the UI
+ qInfo() << "Authed with the wrong user! Please login with the account:" << account->prettyName();
+ if (const auto cred = account->credentials()) {
+ account->credentials()->askFromUser();
+ }
+ return;
+ }
+ account->setDavUser(newUserId);
}
+
QString displayName = objData.value("display-name").toString();
if (!displayName.isEmpty()) {
account->setDavDisplayName(displayName);
}
- // Quota
auto objQuota = objData.value("quota").toObject();
qint64 used = objQuota.value("used").toDouble();
qint64 total = objQuota.value("quota").toDouble();
_jobRestartTimer.start(defaultIntervalT);
_lastInfoReceived = QDateTime::currentDateTime();
- // Avatar Image
if(_fetchAvatarImage) {
auto *job = new AvatarJob(account, account->davUser(), 128, this);
job->setTimeout(20 * 1000);
QObject::connect(job, &AvatarJob::avatarPixmap, this, &UserInfo::slotAvatarImage);
job->start();
+ return;
}
- else
- emit fetchedLastInfo(this);
+
+ emit fetchedLastInfo(this);
}
void UserInfo::slotAvatarImage(const QImage &img)