Prechádzať zdrojové kódy

implemented login (not tested)

Cyamond 4 rokov pred
rodič
commit
8511a94ca3
3 zmenil súbory, kde vykonal 45 pridanie a 3 odobranie
  1. 3 2
      gui/src/IpPopupForm.ui.qml
  2. 41 1
      gui/src/qmlhandler.cpp
  3. 1 0
      gui/src/qmlhandler.h

+ 3 - 2
gui/src/IpPopupForm.ui.qml

@@ -17,6 +17,9 @@ Popup {
         onIpPopupSetStatus: {
             ipPopupStatusText.text = status
         }
+        onIpPopupClose: {
+            popup.close()
+        }
     }
 
     ColumnLayout {
@@ -106,8 +109,6 @@ Popup {
                 if (ipPopupConnectButton.enabled) {
                     // @disable-check M222
                     _qmlHandler.onIpPopupConnectButton(ipPopupIpInput.text, ipPopupUsernameInput.text, ipPopupUsernameInput.text)
-                    // @disable-check M222
-                    popup.close()
                 }
             }
         }

+ 41 - 1
gui/src/qmlhandler.cpp

@@ -22,6 +22,8 @@ int inpipefd[2];
 int outpipefd[2];
 char buf[1025];
 QUrl sendFileUrl = QUrl("");
+QString _USERNAME;
+QString _PASSWORD;
 
 bool programActive = true;
 
@@ -64,6 +66,40 @@ void QMLHandler::handleJSON(string buffer) {
           QString::fromStdString(fileNames[i].asString().c_str()));
     }
   }
+
+  else if (cmd == "connect") {
+    if (root["accept"] == false) {
+      emit ipPopupSetStatus(root["error"].asString().c_str());
+      close(outpipefd[1]);
+      close(inpipefd[0]);
+    }
+  }
+
+  else if (cmd == "version") {
+    if (root["accept"] == true) {
+      write(outpipefd[1], _USERNAME.toUtf8().constData(),
+            strlen(_USERNAME.toUtf8().constData()));
+      write(outpipefd[1], _PASSWORD.toUtf8().constData(),
+            strlen(_PASSWORD.toUtf8().constData()));
+    } else {
+      QString errorMessage = QString::fromStdString(string(
+          "Version mismatch: \nClient: " + root["clientversion"].asString() +
+          "\nServer: " + root["serverversion"].asString()));
+      emit ipPopupSetStatus(errorMessage);
+      close(outpipefd[1]);
+      close(inpipefd[0]);
+    }
+  }
+
+  else if (cmd == "login") {
+    if (root["accept"] == true) {
+      emit ipPopupClose();
+    } else {
+      emit ipPopupSetStatus(root["error"].asString().c_str());
+      close(outpipefd[1]);
+      close(inpipefd[0]);
+    }
+  }
 }
 
 void QMLHandler::readPipeLoop() {
@@ -145,7 +181,8 @@ void QMLHandler::onSettingsSwitchServerButton() {
 }
 
 // Ip Popup
-void QMLHandler::onIpPopupConnectButton(QString ip, QString username, QString password) {
+void QMLHandler::onIpPopupConnectButton(QString ip, QString username,
+                                        QString password) {
   pid_t pid = 0;
 
   pipe(inpipefd);
@@ -171,6 +208,9 @@ void QMLHandler::onIpPopupConnectButton(QString ip, QString username, QString pa
   // TODO: Not hardcoded
   emit footerSetStatus("Connected to " + ip);
 
+  _USERNAME = username;
+  _PASSWORD = password;
+
   close(outpipefd[0]);
   close(inpipefd[1]);
 

+ 1 - 0
gui/src/qmlhandler.h

@@ -38,6 +38,7 @@ signals:
 
   // Ip Popup
   void ipPopupSetStatus(QString status);
+  void ipPopupClose();
 
   // Switch Popup