mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-04-06 22:17:39 +03:00
Support returning a canceled message
This commit is contained in:
parent
b4dab5d8b1
commit
3cf171cbf5
4 changed files with 49 additions and 19 deletions
|
@ -329,10 +329,11 @@ QJsonObject BrowserAction::handleSetLogin(const QJsonObject& json, const QString
|
||||||
const QString groupUuid = decrypted.value("groupUuid").toString();
|
const QString groupUuid = decrypted.value("groupUuid").toString();
|
||||||
const QString realm;
|
const QString realm;
|
||||||
|
|
||||||
|
BrowserService::ReturnValue result = BrowserService::ReturnValue::Success;
|
||||||
if (uuid.isEmpty()) {
|
if (uuid.isEmpty()) {
|
||||||
m_browserService.addEntry(id, login, password, url, submitUrl, realm, group, groupUuid);
|
m_browserService.addEntry(id, login, password, url, submitUrl, realm, group, groupUuid);
|
||||||
} else {
|
} else {
|
||||||
m_browserService.updateEntry(id, uuid, login, password, url, submitUrl);
|
result = m_browserService.updateEntry(id, uuid, login, password, url, submitUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString newNonce = incrementNonce(nonce);
|
const QString newNonce = incrementNonce(nonce);
|
||||||
|
@ -340,7 +341,7 @@ QJsonObject BrowserAction::handleSetLogin(const QJsonObject& json, const QString
|
||||||
QJsonObject message = buildMessage(newNonce);
|
QJsonObject message = buildMessage(newNonce);
|
||||||
message["count"] = QJsonValue::Null;
|
message["count"] = QJsonValue::Null;
|
||||||
message["entries"] = QJsonValue::Null;
|
message["entries"] = QJsonValue::Null;
|
||||||
message["error"] = QString("");
|
message["error"] = getReturnValue(result);
|
||||||
message["hash"] = hash;
|
message["hash"] = hash;
|
||||||
|
|
||||||
return buildResponse(action, message, newNonce);
|
return buildResponse(action, message, newNonce);
|
||||||
|
@ -513,6 +514,19 @@ QString BrowserAction::getErrorMessage(const int errorCode) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString BrowserAction::getReturnValue(const BrowserService::ReturnValue returnValue) const
|
||||||
|
{
|
||||||
|
switch(returnValue) {
|
||||||
|
case BrowserService::ReturnValue::Success:
|
||||||
|
return QString("success");
|
||||||
|
case BrowserService::ReturnValue::Error:
|
||||||
|
return QString("error");
|
||||||
|
case BrowserService::ReturnValue::Canceled:
|
||||||
|
return QString("canceled");
|
||||||
|
}
|
||||||
|
return QString("error");
|
||||||
|
}
|
||||||
|
|
||||||
QString BrowserAction::getDatabaseHash()
|
QString BrowserAction::getDatabaseHash()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_mutex);
|
QMutexLocker locker(&m_mutex);
|
||||||
|
|
|
@ -73,6 +73,7 @@ private:
|
||||||
QJsonObject buildResponse(const QString& action, const QJsonObject& message, const QString& nonce);
|
QJsonObject buildResponse(const QString& action, const QJsonObject& message, const QString& nonce);
|
||||||
QJsonObject getErrorReply(const QString& action, const int errorCode) const;
|
QJsonObject getErrorReply(const QString& action, const int errorCode) const;
|
||||||
QString getErrorMessage(const int errorCode) const;
|
QString getErrorMessage(const int errorCode) const;
|
||||||
|
QString getReturnValue(const BrowserService::ReturnValue returnValue) const;
|
||||||
QString getDatabaseHash();
|
QString getDatabaseHash();
|
||||||
|
|
||||||
QString encryptMessage(const QJsonObject& message, const QString& nonce);
|
QString encryptMessage(const QJsonObject& message, const QString& nonce);
|
||||||
|
|
|
@ -450,7 +450,7 @@ void BrowserService::addEntry(const QString& id,
|
||||||
|
|
||||||
auto db = selectedDb ? selectedDb : selectedDatabase();
|
auto db = selectedDb ? selectedDb : selectedDatabase();
|
||||||
if (!db) {
|
if (!db) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* entry = new Entry();
|
auto* entry = new Entry();
|
||||||
|
@ -489,17 +489,20 @@ void BrowserService::addEntry(const QString& id,
|
||||||
config.save(entry);
|
config.save(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserService::updateEntry(const QString& id,
|
BrowserService::ReturnValue
|
||||||
const QString& uuid,
|
BrowserService::updateEntry(const QString& id,
|
||||||
const QString& login,
|
const QString& uuid,
|
||||||
const QString& password,
|
const QString& login,
|
||||||
const QString& url,
|
const QString& password,
|
||||||
const QString& submitUrl)
|
const QString& url,
|
||||||
|
const QString& submitUrl)
|
||||||
{
|
{
|
||||||
|
ReturnValue result = ReturnValue::Error;
|
||||||
if (thread() != QThread::currentThread()) {
|
if (thread() != QThread::currentThread()) {
|
||||||
QMetaObject::invokeMethod(this,
|
QMetaObject::invokeMethod(this,
|
||||||
"updateEntry",
|
"updateEntry",
|
||||||
Qt::BlockingQueuedConnection,
|
Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(ReturnValue, result),
|
||||||
Q_ARG(QString, id),
|
Q_ARG(QString, id),
|
||||||
Q_ARG(QString, uuid),
|
Q_ARG(QString, uuid),
|
||||||
Q_ARG(QString, login),
|
Q_ARG(QString, login),
|
||||||
|
@ -510,14 +513,14 @@ void BrowserService::updateEntry(const QString& id,
|
||||||
|
|
||||||
auto db = selectedDatabase();
|
auto db = selectedDatabase();
|
||||||
if (!db) {
|
if (!db) {
|
||||||
return;
|
return ReturnValue::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entry* entry = db->rootGroup()->findEntryByUuid(Tools::hexToUuid(uuid));
|
Entry* entry = db->rootGroup()->findEntryByUuid(Tools::hexToUuid(uuid));
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
// If entry is not found for update, add a new one to the selected database
|
// If entry is not found for update, add a new one to the selected database
|
||||||
addEntry(id, login, password, url, submitUrl, "", "", "", db);
|
addEntry(id, login, password, url, submitUrl, "", "", "", db);
|
||||||
return;
|
return ReturnValue::Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the entry password is a reference. If so, update the original entry instead
|
// Check if the entry password is a reference. If so, update the original entry instead
|
||||||
|
@ -526,14 +529,14 @@ void BrowserService::updateEntry(const QString& id,
|
||||||
if (!referenceUuid.isNull()) {
|
if (!referenceUuid.isNull()) {
|
||||||
entry = db->rootGroup()->findEntryByUuid(referenceUuid);
|
entry = db->rootGroup()->findEntryByUuid(referenceUuid);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
return;
|
return ReturnValue::Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString username = entry->username();
|
QString username = entry->username();
|
||||||
if (username.isEmpty()) {
|
if (username.isEmpty()) {
|
||||||
return;
|
return ReturnValue::Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (username.compare(login, Qt::CaseSensitive) != 0
|
if (username.compare(login, Qt::CaseSensitive) != 0
|
||||||
|
@ -557,10 +560,15 @@ void BrowserService::updateEntry(const QString& id,
|
||||||
}
|
}
|
||||||
entry->setPassword(password);
|
entry->setPassword(password);
|
||||||
entry->endUpdate();
|
entry->endUpdate();
|
||||||
|
result = ReturnValue::Success;
|
||||||
|
} else {
|
||||||
|
result = ReturnValue::Canceled;
|
||||||
}
|
}
|
||||||
|
|
||||||
hideWindow();
|
hideWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<Entry*>
|
QList<Entry*>
|
||||||
|
|
|
@ -38,6 +38,13 @@ class BrowserService : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum ReturnValue
|
||||||
|
{
|
||||||
|
Success,
|
||||||
|
Error,
|
||||||
|
Canceled
|
||||||
|
};
|
||||||
|
|
||||||
explicit BrowserService(DatabaseTabWidget* parent);
|
explicit BrowserService(DatabaseTabWidget* parent);
|
||||||
|
|
||||||
bool isDatabaseOpened() const;
|
bool isDatabaseOpened() const;
|
||||||
|
@ -74,12 +81,12 @@ public slots:
|
||||||
const StringPairList& keyList,
|
const StringPairList& keyList,
|
||||||
const bool httpAuth = false);
|
const bool httpAuth = false);
|
||||||
QString storeKey(const QString& key);
|
QString storeKey(const QString& key);
|
||||||
void updateEntry(const QString& id,
|
ReturnValue updateEntry(const QString& id,
|
||||||
const QString& uuid,
|
const QString& uuid,
|
||||||
const QString& login,
|
const QString& login,
|
||||||
const QString& password,
|
const QString& password,
|
||||||
const QString& url,
|
const QString& url,
|
||||||
const QString& submitUrl);
|
const QString& submitUrl);
|
||||||
void databaseLocked(DatabaseWidget* dbWidget);
|
void databaseLocked(DatabaseWidget* dbWidget);
|
||||||
void databaseUnlocked(DatabaseWidget* dbWidget);
|
void databaseUnlocked(DatabaseWidget* dbWidget);
|
||||||
void activateDatabaseChanged(DatabaseWidget* dbWidget);
|
void activateDatabaseChanged(DatabaseWidget* dbWidget);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue