Changes in what I think are the right direction

This commit is contained in:
Zach Fox 2017-08-31 13:15:22 -07:00
parent 914a6bae00
commit 21a73b2f39
5 changed files with 50 additions and 24 deletions

View file

@ -40,8 +40,32 @@ Rectangle {
root.activeView = "needsLogIn";
} else if (isLoggedIn) {
root.activeView = "initialize";
commerce.getSecurityImage();
commerce.getKeyFilePathIfExists();
commerce.getPassphraseSetupStatus();
}
}
onPassphraseSetupStatusResult: {
if (!passphraseIsSetup && root.activeView !== "notSetUp") {
root.activeView = "notSetUp";
} else if (passphraseIsSetup && root.activeView === "initialize") {
commerce.getWalletAuthenticatedStatus();
}
}
onWalletAuthenticatedStatusResult: {
if (!isAuthenticated && !passphraseModal.visible) {
passphraseModal.visible = true;
} else if (isAuthenticated) {
if (passphraseModal.visible) {
passphraseModal.visible = false;
}
if (!securityImageResultReceived) {
commerce.getSecurityImage();
}
if (!keyFilePathIfExistsResultReceived) {
commerce.getKeyFilePathIfExists();
}
}
}
@ -62,16 +86,6 @@ Rectangle {
root.activeView = "walletHome";
}
}
onWalletAuthenticatedStatus: {
if (!isAuthenticated && !passphraseModal.visible) {
passphraseModal.visible = true;
} else if (isAuthenticated && passphraseModal.visible) {
passphraseModal.visible = false;
commerce.getSecurityImage();
commerce.getKeyFilePathIfExists();
}
}
}
SecurityImageModel {
@ -99,7 +113,8 @@ Rectangle {
if (msg.method === 'walletSetup_cancelClicked') {
walletSetupLightbox.visible = false;
} else if (msg.method === 'walletSetup_finished') {
root.activeView = "walletHome";
root.activeView = "initialize";
commerce.getPassphraseSetupStatus();
} else if (msg.method === 'walletSetup_raiseKeyboard') {
root.keyboardRaised = true;
} else if (msg.method === 'walletSetup_lowerKeyboard') {
@ -231,7 +246,7 @@ Rectangle {
PassphraseModal {
id: passphraseModal;
z: 998;
//visible: false;
visible: false;
anchors.top: titleBarContainer.bottom;
anchors.bottom: parent.bottom;
anchors.left: parent.left;

View file

@ -27,7 +27,6 @@ QmlCommerce::QmlCommerce(QQuickItem* parent) : OffscreenQmlDialog(parent) {
connect(wallet.data(), &Wallet::securityImageResult, this, &QmlCommerce::securityImageResult);
connect(ledger.data(), &Ledger::historyResult, this, &QmlCommerce::historyResult);
connect(wallet.data(), &Wallet::keyFilePathIfExistsResult, this, &QmlCommerce::keyFilePathIfExistsResult);
connect(wallet.data(), &Wallet::walletAuthenticatedStatus, this, &QmlCommerce::walletAuthenticatedStatus);
}
void QmlCommerce::buy(const QString& assetId, int cost, const QString& buyerUsername) {
@ -76,12 +75,23 @@ void QmlCommerce::getLoginStatus() {
}
void QmlCommerce::setPassphrase(const QString& passphrase) {
emit passphraseSetupStatusResult(true);
auto wallet = DependencyManager::get<Wallet>();
wallet->setPassphrase(passphrase);
getPassphraseSetupStatus();
}
void QmlCommerce::getPassphraseSetupStatus() {
emit passphraseSetupStatusResult(false);
auto wallet = DependencyManager::get<Wallet>();
// ????? WHAT DO I DO HERE
emit passphraseSetupStatusResult(wallet->getPassphraseIsCached());
}
void QmlCommerce::getWalletAuthenticatedStatus() {
auto wallet = DependencyManager::get<Wallet>();
// ????? WHAT DO I DO HERE
emit walletAuthenticatedStatusResult(wallet->getPassphraseIsCached());
}
void QmlCommerce::getKeyFilePathIfExists() {
auto wallet = DependencyManager::get<Wallet>();
wallet->sendKeyFilePathIfExists();

View file

@ -38,7 +38,7 @@ signals:
void passphraseSetupStatusResult(bool passphraseIsSetup);
void historyResult(QJsonObject result);
void keyFilePathIfExistsResult(const QString& path);
void walletAuthenticatedStatus(bool isAuthenticated);
void walletAuthenticatedStatusResult(bool isAuthenticated);
protected:
Q_INVOKABLE void buy(const QString& assetId, int cost, const QString& buyerUsername = "");
@ -50,6 +50,7 @@ protected:
Q_INVOKABLE void getLoginStatus();
Q_INVOKABLE void setPassphrase(const QString& passphrase);
Q_INVOKABLE void getPassphraseSetupStatus();
Q_INVOKABLE void getWalletAuthenticatedStatus();
Q_INVOKABLE void getKeyFilePathIfExists();
Q_INVOKABLE void reset();
};

View file

@ -55,14 +55,14 @@ QString imageFilePath() {
// use the cached _passphrase if it exists, otherwise we need to prompt
int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) {
// just return a hardcoded pwd for now
auto wallet = DependencyManager::get<Wallet>();
auto passphrase = wallet->getPassphrase();
auto passphrase = DependencyManager::get<Wallet>()->getPassphrase();
if (passphrase) {
strcpy(password, passphrase->toLocal8Bit().constData());
emit wallet->walletAuthenticatedStatus(true);
return static_cast<int>(passphrase->size());
} else {
emit wallet->walletAuthenticatedStatus(false);
// Old comment below...this should never happen once we're here...what if it does?
// ok gotta bring up modal dialog... But right now lets just
// just keep it empty
return 0;
}
}

View file

@ -39,19 +39,19 @@ public:
void setPassphrase(const QString& passphrase);
QString* getPassphrase() { return _passphrase; }
bool getPassphraseIsCached() { return !(_passphrase->isEmpty()); }
void reset();
signals:
void securityImageResult(bool exists);
void keyFilePathIfExistsResult(const QString& path);
void walletAuthenticatedStatus(bool isAuthenticated);
private:
QStringList _publicKeys{};
QPixmap* _securityImage { nullptr };
QByteArray _salt {"iamsalt!"};
QString* _passphrase { new QString("pwd") };
QString* _passphrase { new QString("") };
void updateImageProvider();
bool encryptFile(const QString& inputFilePath, const QString& outputFilePath);