Improve editing of connection password
Previously only a new password was saved if the save password checkbox was checked, Which always started in the unchecked state. Now when editing existing connection the save password checkbox now reflects if a password has been saved. Only when the password field is edited the program will update the saved password. If the save password checkbox is unchecked then clear the save password.
This commit is contained in:
parent
677302b5a7
commit
da19c46d5e
7 changed files with 39 additions and 6 deletions
|
|
@ -102,6 +102,7 @@ ConnectionConfigurationWidget::ConnectionConfigurationWidget(
|
||||||
edtPassword = new QLineEdit;
|
edtPassword = new QLineEdit;
|
||||||
SET_OBJECT_NAME(edtPassword);
|
SET_OBJECT_NAME(edtPassword);
|
||||||
edtPassword->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
edtPassword->setEchoMode(QLineEdit::PasswordEchoOnEdit);
|
||||||
|
connect(edtPassword, &QLineEdit::textEdited, this, &ConnectionConfigurationWidget::passwordEdited);
|
||||||
|
|
||||||
cbSavePassword = new QCheckBox;
|
cbSavePassword = new QCheckBox;
|
||||||
SET_OBJECT_NAME(cbSavePassword);
|
SET_OBJECT_NAME(cbSavePassword);
|
||||||
|
|
@ -212,6 +213,13 @@ void ConnectionConfigurationWidget::setData(const ConnectionConfig &cfg)
|
||||||
edtCrl->setText(cfg.sslCrl());
|
edtCrl->setText(cfg.sslCrl());
|
||||||
|
|
||||||
encodedPassword = cfg.encodedPassword();
|
encodedPassword = cfg.encodedPassword();
|
||||||
|
cbSavePassword->setCheckState(
|
||||||
|
encodedPassword.isEmpty()
|
||||||
|
? Qt::CheckState::Unchecked
|
||||||
|
: Qt::CheckState::Checked
|
||||||
|
);
|
||||||
|
|
||||||
|
passwordChanged = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConnectionConfig ConnectionConfigurationWidget::data() const
|
ConnectionConfig ConnectionConfigurationWidget::data() const
|
||||||
|
|
@ -240,7 +248,12 @@ QString ConnectionConfigurationWidget::group() const
|
||||||
|
|
||||||
bool ConnectionConfigurationWidget::savePassword() const
|
bool ConnectionConfigurationWidget::savePassword() const
|
||||||
{
|
{
|
||||||
return cbSavePassword->isChecked() && !edtPassword->text().isEmpty();
|
return cbSavePassword->isChecked() && !edtPassword->text().isEmpty() && passwordChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ConnectionConfigurationWidget::clearPassword() const
|
||||||
|
{
|
||||||
|
return !cbSavePassword->isChecked();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConnectionConfigurationWidget::testConnection()
|
void ConnectionConfigurationWidget::testConnection()
|
||||||
|
|
@ -278,3 +291,8 @@ void ConnectionConfigurationWidget::handleTestResult(TestConnectionResult result
|
||||||
cmbDbname->setCurrentText(current);
|
cmbDbname->setCurrentText(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionConfigurationWidget::passwordEdited(const QString &)
|
||||||
|
{
|
||||||
|
passwordChanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,9 @@ public:
|
||||||
void setData(const ConnectionConfig &cfg);
|
void setData(const ConnectionConfig &cfg);
|
||||||
ConnectionConfig data() const;
|
ConnectionConfig data() const;
|
||||||
QString group() const;
|
QString group() const;
|
||||||
|
|
||||||
bool savePassword() const;
|
bool savePassword() const;
|
||||||
|
bool clearPassword() const;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void testConnection();
|
void testConnection();
|
||||||
|
|
@ -45,6 +47,7 @@ private:
|
||||||
|
|
||||||
QUuid m_uuid;
|
QUuid m_uuid;
|
||||||
QByteArray encodedPassword;
|
QByteArray encodedPassword;
|
||||||
|
bool passwordChanged;
|
||||||
|
|
||||||
QLabel *lblGroup;
|
QLabel *lblGroup;
|
||||||
QComboBox *cmbbxGroup;
|
QComboBox *cmbbxGroup;
|
||||||
|
|
@ -77,6 +80,7 @@ private:
|
||||||
QFormLayout *formLayout;
|
QFormLayout *formLayout;
|
||||||
|
|
||||||
void handleTestResult(TestConnectionResult result);
|
void handleTestResult(TestConnectionResult result);
|
||||||
|
void passwordEdited(const QString &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONNECTIONCONFIGURATIONWIDGET_H
|
#endif // CONNECTIONCONFIGURATIONWIDGET_H
|
||||||
|
|
|
||||||
|
|
@ -117,9 +117,10 @@ void ConnectionController::saveConnection(ConnectionConfigurationWidget &w)
|
||||||
{
|
{
|
||||||
auto cc = w.data();
|
auto cc = w.data();
|
||||||
auto grp = w.group();
|
auto grp = w.group();
|
||||||
if (w.savePassword()) {
|
if (w.savePassword())
|
||||||
encryptPassword(cc);
|
encryptPassword(cc);
|
||||||
}
|
if (w.clearPassword())
|
||||||
|
cc.setEncodedPassword({});
|
||||||
m_connectionTreeModel->save(grp, cc);
|
m_connectionTreeModel->save(grp, cc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,11 @@ R"__(INSERT OR REPLACE INTO connection
|
||||||
q.bindValue(":sslkey", cc.sslKey());
|
q.bindValue(":sslkey", cc.sslKey());
|
||||||
q.bindValue(":sslrootcert", cc.sslRootCert());
|
q.bindValue(":sslrootcert", cc.sslRootCert());
|
||||||
q.bindValue(":sslcrl", cc.sslCrl());
|
q.bindValue(":sslcrl", cc.sslCrl());
|
||||||
q.bindValue(":password", cc.encodedPassword());
|
auto& encodedPassword = cc.encodedPassword();
|
||||||
|
if (encodedPassword.isEmpty())
|
||||||
|
q.bindValue(":password", QVariant());
|
||||||
|
else
|
||||||
|
q.bindValue(":password", encodedPassword);
|
||||||
|
|
||||||
if (!q.exec()) {
|
if (!q.exec()) {
|
||||||
auto sql_error = q.lastError();
|
auto sql_error = q.lastError();
|
||||||
|
|
|
||||||
|
|
@ -272,7 +272,7 @@ QString ConnectionConfig::makeLongDescription() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray ConnectionConfig::encodedPassword() const
|
const QByteArray& ConnectionConfig::encodedPassword() const
|
||||||
{
|
{
|
||||||
return m_encodedPassword;
|
return m_encodedPassword;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ public:
|
||||||
bool operator==(QUuid id) const { return m_uuid == id; }
|
bool operator==(QUuid id) const { return m_uuid == id; }
|
||||||
|
|
||||||
QString makeLongDescription() const;
|
QString makeLongDescription() const;
|
||||||
QByteArray encodedPassword() const;
|
const QByteArray& encodedPassword() const;
|
||||||
void setEncodedPassword(const QByteArray &encodedPassword);
|
void setEncodedPassword(const QByteArray &encodedPassword);
|
||||||
|
|
||||||
// void write(QDataStream &out) const;
|
// void write(QDataStream &out) const;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
other:
|
||||||
|
- |
|
||||||
|
The way in which editing the password of an existing connection works has been changed to
|
||||||
|
be consistent with creating a new connection and to allow for clearing the saved password
|
||||||
|
by unselecting save password.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue