mirror of
https://git.wownero.com/wowlet/wowlet.git
synced 2024-08-15 01:03:14 +00:00
Merge pull request 'PasswordDialog: misc improvements' (#149) from tobtoht/feather:password_dialog into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/149
This commit is contained in:
commit
d7135393cd
10 changed files with 131 additions and 85 deletions
|
@ -31,7 +31,7 @@ if(DEBUG)
|
|||
set(CMAKE_VERBOSE_MAKEFILE ON)
|
||||
endif()
|
||||
|
||||
set(MONERO_HEAD "d029a63fb75c581fa060447b41d385c595144774")
|
||||
set(MONERO_HEAD "2390030d10b69c357165f82aaf417391a9e11019")
|
||||
set(BUILD_GUI_DEPS ON)
|
||||
set(ARCH "x86-64")
|
||||
set(BUILD_64 ON)
|
||||
|
|
2
monero
2
monero
|
@ -1 +1 @@
|
|||
Subproject commit d029a63fb75c581fa060447b41d385c595144774
|
||||
Subproject commit 2390030d10b69c357165f82aaf417391a9e11019
|
|
@ -610,7 +610,7 @@ void AppContext::onSetRestoreHeight(unsigned int height){
|
|||
}
|
||||
|
||||
this->currentWallet->setWalletCreationHeight(height);
|
||||
this->currentWallet->setPassword(this->walletPassword); // trigger .keys write
|
||||
this->currentWallet->setPassword(this->currentWallet->getPassword()); // trigger .keys write
|
||||
|
||||
// nuke wallet cache
|
||||
const auto fn = this->currentWallet->path();
|
||||
|
|
|
@ -5,17 +5,39 @@
|
|||
#include "ui_passwordchangedialog.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
|
||||
PasswordChangeDialog::PasswordChangeDialog(QWidget *parent)
|
||||
PasswordChangeDialog::PasswordChangeDialog(QWidget *parent, Wallet *wallet)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::PasswordChangeDialog)
|
||||
, m_wallet(wallet)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->icon->setPixmap(QPixmap(":/assets/images/lock.png").scaledToWidth(32, Qt::SmoothTransformation));
|
||||
|
||||
bool noPassword = wallet->getPassword().isEmpty();
|
||||
|
||||
QString warning_str = noPassword ? "Your wallet is not password protected. Use this dialog to add a password to your wallet." :
|
||||
"Your wallet is password protected and encrypted. Use this dialog to change your password.";
|
||||
ui->label_warning->setText(warning_str);
|
||||
|
||||
QPixmap pixmap = noPassword ? QPixmap(":/assets/images/unlock.png") : QPixmap(":/assets/images/lock.png");
|
||||
ui->icon->setPixmap(pixmap.scaledToWidth(32, Qt::SmoothTransformation));
|
||||
|
||||
if (noPassword) {
|
||||
ui->label_currentPassword->hide();
|
||||
ui->lineEdit_currentPassword->hide();
|
||||
}
|
||||
|
||||
connect(ui->lineEdit_newPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch);
|
||||
connect(ui->lineEdit_confirmPassword, &QLineEdit::textChanged, this, &PasswordChangeDialog::passwordsMatch);
|
||||
|
||||
connect(ui->btn_Cancel, &QPushButton::clicked, [this]{
|
||||
this->reject();
|
||||
});
|
||||
connect(ui->btn_OK, &QPushButton::clicked, this, &PasswordChangeDialog::setPassword);
|
||||
|
||||
ui->label_match->setVisible(false);
|
||||
|
||||
this->adjustSize();
|
||||
}
|
||||
|
||||
|
@ -24,15 +46,28 @@ PasswordChangeDialog::~PasswordChangeDialog()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
QString PasswordChangeDialog::getCurrentPassword() {
|
||||
return ui->lineEdit_currentPassword->text();
|
||||
}
|
||||
|
||||
QString PasswordChangeDialog::getNewPassword() {
|
||||
return ui->lineEdit_newPassword->text();
|
||||
}
|
||||
|
||||
void PasswordChangeDialog::passwordsMatch() {
|
||||
bool match = ui->lineEdit_newPassword->text() == ui->lineEdit_confirmPassword->text();
|
||||
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(match);
|
||||
ui->btn_OK->setEnabled(match);
|
||||
ui->label_match->setHidden(match);
|
||||
}
|
||||
|
||||
void PasswordChangeDialog::setPassword() {
|
||||
QString currentPassword = ui->lineEdit_currentPassword->text();
|
||||
QString newPassword = ui->lineEdit_newPassword->text();
|
||||
|
||||
if (currentPassword != m_wallet->getPassword()) {
|
||||
QMessageBox::warning(this, "Error", "Incorrect password");
|
||||
ui->lineEdit_currentPassword->setText("");
|
||||
ui->lineEdit_currentPassword->setFocus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_wallet->setPassword(newPassword)) {
|
||||
QMessageBox::information(this, "Information", "Password changed successfully");
|
||||
this->accept();
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, "Error", QString("Error: %1").arg(m_wallet->errorString()));
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
#define FEATHER_PASSWORDCHANGEDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "libwalletqt/Wallet.h"
|
||||
|
||||
namespace Ui {
|
||||
class PasswordChangeDialog;
|
||||
|
@ -15,16 +16,15 @@ class PasswordChangeDialog : public QDialog
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswordChangeDialog(QWidget *parent = nullptr);
|
||||
explicit PasswordChangeDialog(QWidget *parent, Wallet *wallet);
|
||||
~PasswordChangeDialog() override;
|
||||
|
||||
QString getCurrentPassword();
|
||||
QString getNewPassword();
|
||||
|
||||
private:
|
||||
Ui::PasswordChangeDialog *ui;
|
||||
Wallet *m_wallet;
|
||||
|
||||
void passwordsMatch();
|
||||
void setPassword();
|
||||
};
|
||||
|
||||
#endif //FEATHER_PASSWORDCHANGEDIALOG_H
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>237</height>
|
||||
<width>556</width>
|
||||
<height>309</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -30,7 +30,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<widget class="QLabel" name="label_warning">
|
||||
<property name="text">
|
||||
<string>Your wallet is password protected and encrypted. Use this dialog to change your password.</string>
|
||||
</property>
|
||||
|
@ -41,6 +41,22 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>10</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
|
@ -65,7 +81,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<widget class="QLabel" name="label_currentPassword">
|
||||
<property name="text">
|
||||
<string>Current Password:</string>
|
||||
</property>
|
||||
|
@ -88,14 +104,45 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_match">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Passwords do not match</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_Cancel">
|
||||
<property name="text">
|
||||
<string>Cancel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_OK">
|
||||
<property name="text">
|
||||
<string>OK</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -105,38 +152,5 @@
|
|||
<tabstop>lineEdit_confirmPassword</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>PasswordChangeDialog</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>PasswordChangeDialog</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
|
@ -179,6 +179,11 @@ bool Wallet::setPassword(const QString &password)
|
|||
return m_walletImpl->setPassword(password.toStdString());
|
||||
}
|
||||
|
||||
QString Wallet::getPassword()
|
||||
{
|
||||
return QString::fromStdString(m_walletImpl->getPassword());
|
||||
}
|
||||
|
||||
QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const
|
||||
{
|
||||
return QString::fromStdString(m_walletImpl->address(accountIndex, addressIndex));
|
||||
|
|
|
@ -134,6 +134,9 @@ public:
|
|||
//! changes the password using existing parameters (path, seed, seed lang)
|
||||
Q_INVOKABLE bool setPassword(const QString &password);
|
||||
|
||||
//! get current wallet password
|
||||
Q_INVOKABLE QString getPassword();
|
||||
|
||||
//! returns wallet's public address
|
||||
Q_INVOKABLE QString address(quint32 accountIndex, quint32 addressIndex) const;
|
||||
|
||||
|
|
|
@ -670,6 +670,7 @@ void MainWindow::onWalletOpened() {
|
|||
});
|
||||
|
||||
this->touchbarShowWallet();
|
||||
this->updatePasswordIcon();
|
||||
}
|
||||
|
||||
void MainWindow::onBalanceUpdated(double balance, double unlocked, const QString &balance_str, const QString &unlocked_str) {
|
||||
|
@ -896,28 +897,15 @@ void MainWindow::showConnectionStatusDialog() {
|
|||
}
|
||||
|
||||
void MainWindow::showPasswordDialog() {
|
||||
auto *pdialog = new PasswordChangeDialog(this);
|
||||
int ret = pdialog->exec();
|
||||
if (!ret) return;
|
||||
|
||||
QApplication::setActiveWindow(this);
|
||||
|
||||
QString currentPassword = pdialog->getCurrentPassword();
|
||||
QString newPassword = pdialog->getNewPassword();
|
||||
|
||||
if (currentPassword != m_ctx->walletPassword) {
|
||||
QMessageBox::warning(this, "Error", "Incorrect password");
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_ctx->currentWallet->setPassword(newPassword)) {
|
||||
QMessageBox::information(this, "Information", "Password changed successfully");
|
||||
}
|
||||
else {
|
||||
QMessageBox::warning(this, "Error", QString("Error: %1").arg(m_ctx->currentWallet->errorString()));
|
||||
}
|
||||
|
||||
auto *pdialog = new PasswordChangeDialog(this, m_ctx->currentWallet);
|
||||
pdialog->exec();
|
||||
pdialog->deleteLater();
|
||||
this->updatePasswordIcon();
|
||||
}
|
||||
|
||||
void MainWindow::updatePasswordIcon() {
|
||||
QIcon icon = m_ctx->currentWallet->getPassword().isEmpty() ? QIcon(":/assets/images/unlock.svg") : QIcon(":/assets/images/lock.svg");
|
||||
m_statusBtnPassword->setIcon(icon);
|
||||
}
|
||||
|
||||
void MainWindow::showRestoreHeightDialog() {
|
||||
|
|
|
@ -162,6 +162,7 @@ private:
|
|||
void createUnsignedTxDialog(UnsignedTransaction *tx);
|
||||
void touchbarShowWizard();
|
||||
void touchbarShowWallet();
|
||||
void updatePasswordIcon();
|
||||
|
||||
WalletWizard *createWizard(WalletWizard::Page startPage);
|
||||
|
||||
|
|
Loading…
Reference in a new issue