Browse Source

Resolve "CLI doesn't allow login after a failed attempt"

Sander, Paul 4 years ago
parent
commit
e8f261fadd
4 changed files with 10 additions and 5 deletions
  1. 1 1
      cli/include/userioman.h
  2. 2 2
      cli/src/cmdman.cpp
  3. 5 0
      cli/src/ioman.cpp
  4. 2 2
      cli/test/cmdman_test.cpp

+ 1 - 1
cli/include/userioman.h

@@ -58,7 +58,7 @@ private:
 	/**
 	 * Mutex for synchronized message output
 	 */
-	std::recursive_mutex msgmutex;
+	std::mutex msgmutex;
 
 public:
 	/**

+ 2 - 2
cli/src/cmdman.cpp

@@ -870,10 +870,10 @@ CmdMan::CmdRet CmdMan::handleLogin(Json::Value root) {
 	output["command"] = "login";
 
 	if (!root["accept"].asBool()) {
-		retval.type = error;
+		retval.type = error | close;
 		output["error"] = root["error"].asString();
 		output["accept"] = false;
-		currentState = loginpossible;
+		currentState = connectionpossible;
 	} else {
 		retval.type = print;
 		output["error"] = "";

+ 5 - 0
cli/src/ioman.cpp

@@ -564,6 +564,11 @@ void IoMan::run() {
 	}
 	mainmutex.unlock();
 
+	// Clean up the terminal
+	rl_set_prompt("");
+	rl_replace_line("", 0);
+	rl_redisplay();
+
 	// Remove the handler
 	rl_callback_handler_remove();
 }

+ 2 - 2
cli/test/cmdman_test.cpp

@@ -311,12 +311,12 @@ TEST(testLogin, Negative) {
 	EXPECT_EQ(retvalCmd.msg["pass"].asString(), "paswod");
 	EXPECT_FALSE(retvalCmd.msg["cancel"].asBool());
 
-	EXPECT_EQ(retvalHdl.type, CmdMan::error);
+	EXPECT_EQ(retvalHdl.type, CmdMan::error | CmdMan::close);
 	EXPECT_EQ(retvalHdl.msg["command"].asString(), "login");
 	EXPECT_FALSE(retvalHdl.msg["accept"].asBool());
 	EXPECT_THAT(retvalHdl.msg["error"].asString(), testing::HasSubstr("fancy error string"));
 
-	EXPECT_TRUE(cm.isVersionChecked());
+	EXPECT_TRUE(cm.isNotConnected());
 }
 
 TEST(testLogin, TooFewArgs) {