aboutsummaryrefslogtreecommitdiff
path: root/src/Window.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2018-10-27 13:51:10 +0200
committerdec05eba <dec05eba@protonmail.com>2018-10-27 13:51:14 +0200
commit09d059f8e2056ea05aaa6e71b56817f28d0a230a (patch)
treefbd5bd1b218df1cb4e9dbf8a1e0de4e53c50625f /src/Window.cpp
parent8089e8e88fb145b4b954c310a0eda2ec647259cd (diff)
Add register window
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)
{