Skip to content

Commit

Permalink
Fix multiple triggers to password generation signal
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Oct 17, 2021
1 parent c5e1d94 commit 77b1abb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
22 changes: 12 additions & 10 deletions src/browser/BrowserAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ namespace

const int BrowserAction::MaxUrlLength = 256;

BrowserAction::BrowserAction()
{
QObject::connect(browserService(), &BrowserService::passwordGenerated, [=](QString password, QString nonce) {
const QString newNonce = incrementNonce(nonce);
QJsonObject message = buildMessage(newNonce);
message["password"] = password;

browserService()->sendPassword(buildResponse("generate-password", message, newNonce));
});
}

QJsonObject BrowserAction::processClientMessage(const QJsonObject& json)
{
if (json.isEmpty()) {
Expand Down Expand Up @@ -319,16 +330,7 @@ QJsonObject BrowserAction::handleGeneratePassword(const QJsonObject& json, const
auto errorMessage = getErrorReply(action, ERROR_KEEPASS_ACTION_CANCELLED_OR_DENIED);
auto nonce = json.value("nonce").toString();

browserService()->showPasswordGenerator(errorMessage);

QObject::connect(browserService(), &BrowserService::passwordGenerated, [=](QString password) {
const QString newNonce = incrementNonce(nonce);
QJsonObject message = buildMessage(newNonce);
message["password"] = password;

browserService()->sendPassword(buildResponse(action, message, newNonce));
});

browserService()->showPasswordGenerator(errorMessage, nonce);
return QJsonObject();
}

Expand Down
2 changes: 1 addition & 1 deletion src/browser/BrowserAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QJsonObject;
class BrowserAction
{
public:
explicit BrowserAction() = default;
explicit BrowserAction();
~BrowserAction() = default;

QJsonObject processClientMessage(const QJsonObject& json);
Expand Down
9 changes: 4 additions & 5 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ QString BrowserService::getCurrentTotp(const QString& uuid)
return {};
}

void BrowserService::showPasswordGenerator(const QJsonObject& errorMessage)
void BrowserService::showPasswordGenerator(const QJsonObject& errorMessage, const QString& nonce)
{
if (!m_passwordGenerator) {
m_passwordGenerator.reset(PasswordGeneratorWidget::popupGenerator());
Expand All @@ -322,10 +322,9 @@ void BrowserService::showPasswordGenerator(const QJsonObject& errorMessage)
hideWindow();
});

connect(m_passwordGenerator.data(),
&PasswordGeneratorWidget::appliedPassword,
this,
&BrowserService::passwordGenerated);
connect(m_passwordGenerator.data(), &PasswordGeneratorWidget::appliedPassword, [=](QString password) {
emit passwordGenerated(password, nonce);
});
}

raiseWindow();
Expand Down
4 changes: 2 additions & 2 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BrowserService : public QObject
QJsonObject getDatabaseGroups();
QJsonObject createNewGroup(const QString& groupName);
QString getCurrentTotp(const QString& uuid);
void showPasswordGenerator(const QJsonObject& errorMessage);
void showPasswordGenerator(const QJsonObject& errorMessage, const QString& nonce);
void sendPassword(const QJsonObject& message);

void addEntry(const QString& dbid,
Expand Down Expand Up @@ -96,7 +96,7 @@ class BrowserService : public QObject

signals:
void requestUnlock();
void passwordGenerated(const QString& password);
void passwordGenerated(const QString& password, const QString& nonce);

public slots:
void databaseLocked(DatabaseWidget* dbWidget);
Expand Down

0 comments on commit 77b1abb

Please sign in to comment.