Przeglądaj źródła

fix mistake in login field to variable assignment, ensure correct boolean usage from json, exchange some logic

Missingmew 5 lat temu
rodzic
commit
3f69509d9f
2 zmienionych plików z 10 dodań i 9 usunięć
  1. 1 1
      gui/src/IpPopupForm.ui.qml
  2. 9 8
      gui/src/qmlhandler.cpp

+ 1 - 1
gui/src/IpPopupForm.ui.qml

@@ -108,7 +108,7 @@ Popup {
                 // @disable-check M223
                 if (ipPopupConnectButton.enabled) {
                     // @disable-check M222
-                    _qmlHandler.onIpPopupConnectButton(ipPopupIpInput.text, ipPopupUsernameInput.text, ipPopupUsernameInput.text)
+                    _qmlHandler.onIpPopupConnectButton(ipPopupIpInput.text, ipPopupUsernameInput.text, ipPopupPasswordInput.text)
                 }
             }
         }

+ 9 - 8
gui/src/qmlhandler.cpp

@@ -47,6 +47,7 @@ void QMLHandler::handleJSON(string buffer) {
   }
   const Json::Value command = root["command"];
   string cmd = command.asString();
+  qInfo() << QString::fromStdString("Received command " + cmd);
 
   if (cmd == "status") {
     emit footerSetStatus(root["response"].asString().c_str());
@@ -68,7 +69,12 @@ void QMLHandler::handleJSON(string buffer) {
   }
 
   else if (cmd == "connect") {
-    if (root["accept"] == false) {
+    if(root["accept"].asBool()) {
+      write(outpipefd[1], (_USERNAME + "\n").toUtf8().constData(),
+            strlen((_USERNAME + "\n").toUtf8().constData()));
+      write(outpipefd[1], (_PASSWORD + "\n").toUtf8().constData(),
+            strlen((_PASSWORD + "\n").toUtf8().constData()));
+    } else {
       emit ipPopupSetStatus(root["error"].asString().c_str());
       close(outpipefd[1]);
       close(inpipefd[0]);
@@ -76,12 +82,7 @@ void QMLHandler::handleJSON(string buffer) {
   }
 
   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 {
+    if (root["accept"].asBool() == false) {
       QString errorMessage = QString::fromStdString(string(
           "Version mismatch: \nClient: " + root["clientversion"].asString() +
           "\nServer: " + root["serverversion"].asString()));
@@ -92,7 +93,7 @@ void QMLHandler::handleJSON(string buffer) {
   }
 
   else if (cmd == "login") {
-    if (root["accept"] == true) {
+    if (root["accept"].asBool() == true) {
       emit ipPopupClose();
     } else {
       emit ipPopupSetStatus(root["error"].asString().c_str());