If askForOptionalPassword is enabled preset a random password

This is the same approach used on the server side. Turns out I quite
like it, this avoids popping up a dialog to the user and since she won't
know the password she'll have to set a new one anyway or disable it.

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
Kevin Ottens 2020-10-06 14:01:53 +02:00 committed by Kevin Ottens (Rebase PR Action)
parent 099d25a56c
commit e78312f094

View file

@ -25,6 +25,7 @@
#include "configfile.h"
#include "theme.h"
#include "thumbnailjob.h"
#include "wordlist.h"
#include <QFileInfo>
#include <QFileIconProvider>
@ -33,6 +34,20 @@
#include <QPushButton>
#include <QFrame>
namespace {
QString createRandomPassword()
{
const auto words = OCC::WordList::getRandomWords(10);
const auto addFirstLetter = [](const QString &current, const QString &next) {
return current + next.at(0);
};
return std::accumulate(std::cbegin(words), std::cend(words), QString(), addFirstLetter);
}
}
namespace OCC {
static const int thumbnailSize = 40;
@ -303,7 +318,9 @@ void ShareDialog::showSharingUi()
void ShareDialog::slotCreateLinkShare()
{
if(_manager) {
_manager->createLinkShare(_sharePath, QString(), QString());
const auto askOptionalPassword = _accountState->account()->capabilities().sharePublicLinkAskOptionalPassword();
const auto password = askOptionalPassword ? createRandomPassword() : QString();
_manager->createLinkShare(_sharePath, QString(), password);
}
}