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