diff --git a/src/DataStore/ChatDataStore.cpp b/src/DataStore/ChatDataStore.cpp index 5563fab..82f9db3 100644 --- a/src/DataStore/ChatDataStore.cpp +++ b/src/DataStore/ChatDataStore.cpp @@ -33,6 +33,18 @@ ChatItem ChatDataStore::getData(QString key) return this->data[key]; } +QString ChatDataStore::getPassword() +{ + + return _password; +} + +void ChatDataStore::setPassword(QString password) +{ + + _password = password; +} + QString ChatDataStore::dump() { json chats; diff --git a/src/DataStore/ChatDataStore.h b/src/DataStore/ChatDataStore.h index 7fb0998..c1233b6 100644 --- a/src/DataStore/ChatDataStore.h +++ b/src/DataStore/ChatDataStore.h @@ -25,6 +25,11 @@ class ChatDataStore std::map getAllNewContactRequests(); std::map getAllOldContactRequests(); std::map getAllMemos(); + QString getPassword(); + + void setPassword(QString Password); + QString _password; + QString dump(); ~ChatDataStore() diff --git a/src/chatmodel.cpp b/src/chatmodel.cpp index 7fda03a..2fcbbf6 100644 --- a/src/chatmodel.cpp +++ b/src/chatmodel.cpp @@ -454,7 +454,7 @@ Tx MainWindow::createTxFromChatPage() { QString pubkey = this->getPubkeyByAddress(addr); - QString passphrase = this->getPassword(); + QString passphrase = DataStore::getChatDataStore()->getPassword(); QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); @@ -783,7 +783,7 @@ Tx MainWindow::createTxForSafeContactRequest() QString memo = contactRequest.getMemo(); // QString privkey = rpc->fetchPrivKey(myAddr); - QString passphrase = this->getPassword(); + QString passphrase = DataStore::getChatDataStore()->getPassword(); QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); diff --git a/src/controller.cpp b/src/controller.cpp index 495ee7d..6d02a40 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -11,10 +11,6 @@ #include "Model/ChatItem.h" #include "DataStore/DataStore.h" -/*template<> -DataStore* DataStore::instance = nullptr; -template<> -bool DataStore::instanced = false;*/ ChatModel *chatModel = new ChatModel(); Chat *chat = new Chat(); ContactModel *contactModel = new ContactModel(); @@ -971,7 +967,7 @@ void Controller::refreshTransactions() { if ((memo.startsWith("{") == false) && (headerbytes.length() > 20)) { - QString passphrase = main->getPassword(); + QString passphrase = DataStore::getChatDataStore()->getPassword(); QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); @@ -1227,7 +1223,7 @@ void Controller::refreshTransactions() { chatModel->addMemo(txid, headerbytes); }else{} - QString passphrase = main->getPassword(); + QString passphrase = DataStore::getChatDataStore()->getPassword(); QString hashEncryptionKey = passphrase; int length = hashEncryptionKey.length(); diff --git a/src/firsttimewizard.cpp b/src/firsttimewizard.cpp index 438f737..ffcfd84 100644 --- a/src/firsttimewizard.cpp +++ b/src/firsttimewizard.cpp @@ -3,6 +3,8 @@ #include "ui_newseed.h" #include "ui_restoreseed.h" #include "ui_newwallet.h" +#include "mainwindow.h" +#include "DataStore/DataStore.h" #include "../lib/silentdragonlitelib.h" @@ -38,31 +40,75 @@ int FirstTimeWizard::nextId() const { NewOrRestorePage::NewOrRestorePage(FirstTimeWizard *parent) : QWizardPage(parent) { setTitle("Create or Restore wallet."); + + QWidget* pageWidget = new QWidget(); Ui_CreateWalletForm form; form.setupUi(pageWidget); + - // Exclusive buttons + auto fnPasswordEdited = [=](const QString&) { + // Enable the Finish button if the passwords match. + QString Password = form.txtPassword->text(); + + if (!form.txtPassword->text().isEmpty() && + form.txtPassword->text() == form.txtConfirmPassword->text() && Password.size() >= 16) { + + form.lblPasswordMatch->setText(""); + parent->button(QWizard::CommitButton)->setEnabled(true); + setButtonText(QWizard::CommitButton, "Next"); + form.radioRestoreWallet->setEnabled(true); + form.radioNewWallet->setEnabled(true); + form.radioNewWallet->setChecked(true); + qDebug()<<"PW :"<setPassword(Password); + //main->setPassword(Password); + + //qDebug()<<"Objekt gesetzt"; + + + // Exclusive buttons QObject::connect(form.radioNewWallet, &QRadioButton::clicked, [=](bool checked) { if (checked) { form.radioRestoreWallet->setChecked(false); + } }); QObject::connect(form.radioRestoreWallet, &QRadioButton::clicked, [=](bool checked) { if (checked) { form.radioNewWallet->setChecked(false); + } }); - form.radioNewWallet->setChecked(true); + - registerField("intro.new", form.radioNewWallet); + + } else { + form.lblPasswordMatch->setText(tr("Passphrase don't match or You have entered too few letters (16 minimum)")); + + parent->button(QWizard::CommitButton)->setEnabled(false); + form.radioRestoreWallet->setEnabled(false); + form.radioNewWallet->setEnabled(false); + } + + }; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(pageWidget); setLayout(layout); + + + QObject::connect(form.txtConfirmPassword, &QLineEdit::textChanged, fnPasswordEdited); + QObject::connect(form.txtPassword, &QLineEdit::textChanged, fnPasswordEdited); + registerField("intro.new", form.radioNewWallet); + form.radioRestoreWallet->setEnabled(false); + form.radioNewWallet->setEnabled(false); setCommitPage(true); - setButtonText(QWizard::CommitButton, "Next"); + + } NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) { @@ -81,6 +127,7 @@ NewSeedPage::NewSeedPage(FirstTimeWizard *parent) : QWizardPage(parent) { void NewSeedPage::initializePage() { // Call the library to create a new wallet. + char* resp = litelib_initialize_new(parent->dangerous, parent->server.toStdString().c_str()); QString reply = litelib_process_response(resp); @@ -90,7 +137,11 @@ void NewSeedPage::initializePage() { } else { QString seed = QString::fromStdString(parsed["seed"].get()); form.txtSeed->setPlainText(seed); + + } + + } // Will be called just before closing. Make sure we can save the seed in the wallet @@ -175,4 +226,4 @@ bool RestoreSeedPage::validatePage() { return true; } } -} \ No newline at end of file +} diff --git a/src/firsttimewizard.h b/src/firsttimewizard.h index 276c0cd..8d84b61 100644 --- a/src/firsttimewizard.h +++ b/src/firsttimewizard.h @@ -5,11 +5,18 @@ #include "ui_newseed.h" #include "ui_restoreseed.h" +#include "mainwindow.h" + + class FirstTimeWizard: public QWizard { + + + public: FirstTimeWizard(bool dangerous, QString server); + protected: int nextId() const; @@ -27,11 +34,16 @@ private: friend class NewOrRestorePage; friend class NewSeedPage; friend class RestoreSeedPage; + + + }; class NewOrRestorePage: public QWizardPage { public: + NewOrRestorePage(FirstTimeWizard* parent); + }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 22bc64f..bf5b464 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -31,6 +31,7 @@ #include "Crypto/passwd.h" #include "Crypto/FileEncryption.h" #include "DataStore/DataStore.h" +#include "firsttimewizard.h" using json = nlohmann::json; @@ -52,8 +53,6 @@ auto dirwalletenc = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLo auto dirwalletbackup = QDir(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).filePath(".silentdragonlite/silentdragonlite-wallet.datBackup"); #endif - - MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -289,10 +288,10 @@ void MainWindow::closeEvent(QCloseEvent* event) { s.sync(); - + // Let the RPC know to shut down any running service. rpc->shutdownhushd(); - int passphraselenght = this->getPassword().length(); + int passphraselenght = DataStore::getChatDataStore()->getPassword().length(); // Check is encryption is ON for SDl if(passphraselenght > 0) @@ -305,7 +304,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { fileoldencryption.remove(); // Encrypt our wallet.dat - QString str = this->getPassword(); + QString str = DataStore::getChatDataStore()->getPassword(); // QString str = ed.txtPassword->text(); // data comes from user inputs int length = str.length(); @@ -401,7 +400,7 @@ void MainWindow::encryptWallet() { QString passphrase = ed.txtPassword->text(); // data comes from user inputs int length = passphrase.length(); - this->setPassword(passphrase); + DataStore::getChatDataStore()->setPassword(passphrase); char *sequence = NULL; sequence = new char[length+1]; @@ -561,7 +560,7 @@ void MainWindow::removeWalletEncryptionStartUp() { { QString password = ed.txtPassword->text(); // data comes from user inputs int length = password.length(); - this->setPassword(password); + DataStore::getChatDataStore()->setPassword(password); char *sequence = NULL; sequence = new char[length+1]; strncpy(sequence, password.toLocal8Bit(), length +1); @@ -663,6 +662,7 @@ void MainWindow::setupStatusBar() { loadingMovie->start(); loadingLabel->setAttribute(Qt::WA_NoSystemBackground); loadingLabel->setMovie(loadingMovie); + ui->statusBar->addPermanentWidget(loadingLabel); loadingLabel->setVisible(false); @@ -1159,7 +1159,6 @@ void MainWindow::setupBalancesTab() { ui->lblSyncWarning->setVisible(false); ui->lblSyncWarningReceive->setVisible(false); - // Setup context menu on balances tab ui->balancesTable->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(ui->balancesTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { @@ -1191,6 +1190,8 @@ void MainWindow::setupBalancesTab() { menu.exec(ui->balancesTable->viewport()->mapToGlobal(pos)); }); + + qDebug()<<"PW :"<getPassword(); } void MainWindow::setuphushdTab() { diff --git a/src/mainwindow.h b/src/mainwindow.h index 53032df..62ff3f3 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -5,7 +5,7 @@ #include "logger.h" #include "recurring.h" - +#include "firsttimewizard.h" // Forward declare to break circular dependency. class Controller; @@ -59,6 +59,7 @@ public: void addPubkey(QString requestZaddr, QString pubkey); + void replaceWormholeClient(WormholeClient* newClient); bool isWebsocketListening(); @@ -67,10 +68,7 @@ public: void saveContact(); void saveandsendContact(); void showRequesthush(); - // void setmaxlenChat(int len); - // void updateDisplay(); - - + void balancesReady(); void payhushURI(QString uri = "", QString myAddr = ""); @@ -113,6 +111,7 @@ private: bool fileExists(QString path); void closeEvent(QCloseEvent* event); void closeEventpw(QCloseEvent* event); + QString _password; void setupSendTab(); @@ -122,7 +121,6 @@ private: void setuphushdTab(); void setupchatTab(); void renderContactRequest(); - // void setLenDisplayLabel(QLabel* label); void updateContacts(); void updateChat(); @@ -131,7 +129,7 @@ private: void setupStatusBar(); void clearSendForm(); - QString _password; + Tx createTxFromSendPage(); bool confirmTx(Tx tx, RecurringPaymentInfo* rpi); diff --git a/src/newseed.ui b/src/newseed.ui index ed5d9ae..7657542 100644 --- a/src/newseed.ui +++ b/src/newseed.ui @@ -6,15 +6,15 @@ 0 0 - 400 - 300 + 427 + 416 Form - + This is your new wallet's seed phrase. PLEASE BACK IT UP SECURELY. @@ -24,17 +24,7 @@ - - - - The seed phrase is the only way to restore the wallet. If you forget the seed phrase, THERE IS NO WAY TO RESTORE YOUR WALLET AND THE FUNDS in it - - - true - - - - + @@ -56,6 +46,16 @@ + + + + The seed phrase is the only way to restore the wallet. If you forget the seed phrase, THERE IS NO WAY TO RESTORE YOUR WALLET AND THE FUNDS in it + + + true + + + diff --git a/src/newwallet.ui b/src/newwallet.ui index 9cf34c5..ac2a5af 100644 --- a/src/newwallet.ui +++ b/src/newwallet.ui @@ -6,16 +6,16 @@ 0 0 - 400 - 300 + 437 + 381 Form - - + + 0 @@ -25,18 +25,18 @@ - + - + - Restore wallet from seed + Create a new Wallet - + - Restore an existing wallet, using the 24-word seed. + Create a new wallet with a randomly generated seed. true @@ -46,8 +46,63 @@ - - + + + + Qt::Horizontal + + + + + + + color: red; + + + Passphrase don't match + + + Qt::AlignCenter + + + + + + + <html><head/><body><p>16 letters minimum</p></body></html> + + + + + + + Encryption Passphrase: + + + + + + + QLineEdit::Password + + + + + + + Confirm Passphrase: + + + + + + + QLineEdit::Password + + + + + 0 @@ -57,18 +112,18 @@ - + - + - Create a new Wallet + Restore wallet from seed - + - Create a new wallet with a randomly generated seed. + Restore an existing wallet, using the 24-word seed. true