From 09d059f8e2056ea05aaa6e71b56817f28d0a230a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 27 Oct 2018 13:51:10 +0200 Subject: Add register window --- src/Window.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/Window.cpp') diff --git a/src/Window.cpp b/src/Window.cpp index 72a3d9d..970242d 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -21,10 +21,15 @@ namespace dchat stack.add(loginWindow, "login"); stack.add(chatWindow, "chat"); - show_all(); + overlay->show(); + windowNotification->show_all(); + stack.show(); + chatWindow.show_all(); + loginWindow.show(); loginWindow.setLoginHandler([this, windowNotification](const Glib::ustring &username, const Glib::ustring &password) { + std::lock_guard lock(databaseCallbackMutex); if(!database) { windowNotification->show("You are not connected to the bootstrap node yet! please wait..."); @@ -35,7 +40,7 @@ namespace dchat { fprintf(stderr, "Trying to login with username %s\n", username.raw().c_str()); auto storedNodes = database->getStoredNodeUserInfoDecrypted(username.raw(), password.raw()); - fprintf(stderr, "Successfully logged in as %s\n", username.raw().c_str()); + windowNotification->show(Glib::ustring("Successfully logged in as ") + username); stack.set_visible_child(chatWindow); for(auto &nodeInfo : storedNodes) @@ -51,6 +56,37 @@ namespace dchat } }); + loginWindow.setRegisterHandler([this, windowNotification](const Glib::ustring &username, const Glib::ustring &password) + { + std::lock_guard lock(databaseCallbackMutex); + if(!database) + { + windowNotification->show("You are not connected to the bootstrap node yet! please wait..."); + return; + } + + try + { + fprintf(stderr, "Trying to register username %s\n", username.raw().c_str()); + database->storeUserWithoutNodes(username.raw(), password.raw()); + windowNotification->show(Glib::ustring("Successfully registered user ") + username); + stack.set_visible_child(chatWindow); + } + catch(std::exception &e) + { + Glib::ustring errMsg = "Failed to register username "; + errMsg += username.raw(); + errMsg += ", reason: "; + errMsg += e.what(); + windowNotification->show(errMsg); + } + }); + + loginWindow.setRegisterPasswordMismatch([windowNotification] + { + windowNotification->show("Passwords do not match"); + }); + odhtdb::DatabaseCallbackFuncs callbackFuncs; callbackFuncs.createNodeCallbackFunc = [this](const odhtdb::DatabaseCreateNodeRequest &request) { -- cgit v1.2.3