Validate uid certification input.

Check all input in the popup before calling KeyEdit::
This commit is contained in:
SET
2020-11-22 14:48:27 +01:00
parent 6f15ab4d06
commit 14964f9862
3 changed files with 30 additions and 3 deletions

View File

@@ -145,10 +145,9 @@ void KeyEdit::OnUidValidityClicked(WTreeTableNode* uidNode, vector<WString>& pri
void KeyEdit::EditUidValidity() void KeyEdit::EditUidValidity()
{ {
vector<uint>& uidsToSign = m_popupCertifyUid->GetUidsToSign(); if (!m_popupCertifyUid->Validate())
if (uidsToSign.size() == 0)
{ {
m_owner->m_tmwMessage->SetText(TR("NoUidSelected")); m_owner->m_tmwMessage->SetText(TR("InvalidInput"));
return; return;
} }
const WString signingKey = m_popupCertifyUid->GetSelectedKey(); const WString signingKey = m_popupCertifyUid->GetSelectedKey();
@@ -157,6 +156,7 @@ void KeyEdit::EditUidValidity()
GpgME::Error e; GpgME::Error e;
if (m_popupCertifyUid->WhatToDo() == PopupCertifyUserId::CertifyUid) if (m_popupCertifyUid->WhatToDo() == PopupCertifyUserId::CertifyUid)
{ {
vector<uint>& uidsToSign = m_popupCertifyUid->GetUidsToSign();
int options = m_popupCertifyUid->GetCertifyOptions(); int options = m_popupCertifyUid->GetCertifyOptions();
e = gpgWorker.CertifyKey(signingKey.toUTF8().c_str(), e = gpgWorker.CertifyKey(signingKey.toUTF8().c_str(),
keyToSign.toUTF8().c_str(), keyToSign.toUTF8().c_str(),

View File

@@ -28,6 +28,7 @@ PopupCertifyUserId::PopupCertifyUserId(WWidget * anchorWidget, TransientMessageW
m_cbOptionExportable = NULL; m_cbOptionExportable = NULL;
m_cbOptionNonRevocable = NULL; m_cbOptionNonRevocable = NULL;
// m_cbOptionTrust = NULL; // m_cbOptionTrust = NULL;
m_cbConfirm = NULL;
m_lblPassphrase = NULL; m_lblPassphrase = NULL;
m_lePassphrase = NULL; m_lePassphrase = NULL;
m_btnApply = NULL; m_btnApply = NULL;
@@ -98,6 +99,9 @@ void PopupCertifyUserId::Create(vector<WString>& privateKeys,
m_bgWhat->setCheckedButton(rbCertifyUid); m_bgWhat->setCheckedButton(rbCertifyUid);
vblMain->addLayout(unique_ptr<WHBoxLayout> (hblWhat)); vblMain->addLayout(unique_ptr<WHBoxLayout> (hblWhat));
m_cbConfirm = new WCheckBox(TR("Confirm"));
vblMain->addWidget(unique_ptr<WCheckBox> (m_cbConfirm));
WHBoxLayout * hblButtons = new WHBoxLayout(); WHBoxLayout * hblButtons = new WHBoxLayout();
WPushButton * btnClose = new WPushButton(TR("Close")); WPushButton * btnClose = new WPushButton(TR("Close"));
hblButtons->addWidget(unique_ptr<WPushButton> (btnClose)); hblButtons->addWidget(unique_ptr<WPushButton> (btnClose));
@@ -279,3 +283,20 @@ void PopupCertifyUserId::OnButtonGroupWhat(WRadioButton* btn)
== What::RevokeUidCertification); == What::RevokeUidCertification);
} }
bool PopupCertifyUserId::Validate() const
{
if (!m_cbConfirm->isChecked() || m_lePassphrase->text().empty())
return false;
if (m_bgWhat->checkedId() == What::CertifyUid)
{
if (m_uidsToSign.size() == 0)
return false;
}
else
{
if (m_uidsToRevokeCertification.size() == 0)
return false;
}
return true;
}

View File

@@ -149,6 +149,11 @@ public:
{ {
return m_btnApply; return m_btnApply;
} }
/**
* Check required parameters are set and confirmed.
* @return
*/
bool Validate() const;
private: private:
TransientMessageWidget * m_tmwMessage; TransientMessageWidget * m_tmwMessage;
WContainerWidget * m_cwMain; WContainerWidget * m_cwMain;
@@ -163,6 +168,7 @@ private:
// WCheckBox * m_cbOptionTrust; // Always fails // WCheckBox * m_cbOptionTrust; // Always fails
WText * m_lblPassphrase; WText * m_lblPassphrase;
WLineEdit * m_lePassphrase; WLineEdit * m_lePassphrase;
WCheckBox * m_cbConfirm;
WPushButton * m_btnApply; WPushButton * m_btnApply;
vector<uint> m_uidsToSign; vector<uint> m_uidsToSign;