aboutsummaryrefslogtreecommitdiff
path: root/src/Window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Window.cpp')
-rw-r--r--src/Window.cpp40
1 files changed, 38 insertions, 2 deletions
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<std::mutex> 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<std::mutex> 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)
{