Skip to content

Commit

Permalink
If askForOptionalPassword is enabled preset a random password
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Kevin Ottens authored and er-vin committed Oct 7, 2020
1 parent 099d25a commit e78312f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/gui/sharedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "configfile.h"
#include "theme.h"
#include "thumbnailjob.h"
#include "wordlist.h"

#include <QFileInfo>
#include <QFileIconProvider>
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit e78312f

Please sign in to comment.