ソースを参照

first implementation of deleteme cmd for CLI

Denys 5 年 前
コミット
d179f18e6b
2 ファイル変更32 行追加0 行削除
  1. 3 0
      cli/include/cmdman.h
  2. 29 0
      cli/src/cmdman.cpp

+ 3 - 0
cli/include/cmdman.h

@@ -120,6 +120,8 @@ private:
   CmdRet cmdLogin(vector<string> args);
   const string descSignup = "sign up and login to the server";
   CmdRet cmdSignup(vector<string> args);
+  const string descDeleteme = "delete the user you are currently logged in as (needs to be confirmed with the password)";
+  CmdRet cmdDeleteme(vector<string> args);
 
   /**
    * Method prototypes for commands used internally
@@ -145,6 +147,7 @@ private:
   CmdRet handleVersion(Json::Value);
   CmdRet handleLogin(Json::Value);
   CmdRet handleSignup(Json::Value);
+  CmdRet handleDeleteme(Json::Value);
 };
 
 #endif

+ 29 - 0
cli/src/cmdman.cpp

@@ -32,6 +32,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
   execmap["putdata"] = &CmdMan::cmdPutdata;
   execmap["getdata"] = &CmdMan::cmdGetdata;
   execmap["listdata"] = &CmdMan::cmdListdata;
+  execmap["deleteme"] = &CmdMan::cmdDeleteme;
 
   /* initialize description map */
   helpmap["help"] = descHelp;
@@ -40,6 +41,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
   helpmap["put"] = descPut;
   helpmap["get"] = descGet;
   helpmap["list"] = descList;
+  helpmap["deleteme"] = descDeleteme;
 
   /* initialize handle command map */
   handlemap["status"] = &CmdMan::handleStatus;
@@ -53,6 +55,7 @@ CmdMan::CmdMan(FileMan &fm, void (*dpf)(string)) : fileman(fm) {
   handlemap["login"] = &CmdMan::handleLogin;
   handlemap["signup"] = &CmdMan::handleSignup;
   handlemap["listdata"] = &CmdMan::handleListdata;
+  handlemap["deleteme"] = &CmdMan::handleDeleteme;
 
   debugprintfunc = dpf;
 }
@@ -253,6 +256,19 @@ CmdMan::CmdRet CmdMan::execute(string cmd, vector<string> args) {
   return (this->*(execmap[cmd]))(args);
 }
 
+CmdMan::CmdRet CmdMan::cmdDeleteme(vector<string> args) {
+  CmdRet retval;
+  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+  Json::Value root;
+
+  root["command"] = "deleteme";
+  root["pass"] = args[0];
+  retval.type = send;
+  retval.msg = root;
+
+  return retval;
+}
+
 /* login and signup commands */
 CmdMan::CmdRet CmdMan::cmdLogin(vector<string> args) {
   CmdRet retval;
@@ -649,3 +665,16 @@ CmdMan::CmdRet CmdMan::handleSignup(Json::Value root) {
 
   return retval;
 }
+
+CmdMan::CmdRet CmdMan::handleDeleteme(Json::Value root) {
+  CmdRet retval;
+  DEBUGPRINT(string(__PRETTY_FUNCTION__) + " begin");
+
+  if (!root["accept"].asBool()) {
+    retval.type = error;
+  } else {
+    retval.type = close;
+  }
+  retval.msg = root;
+  return retval;
+}