|
@@ -13,6 +13,7 @@ JsonCommander::JsonCommander(FileManager &fileManager)
|
|
|
commandsMap["get"] = &JsonCommander::executeGet;
|
|
|
commandsMap["getdata"] = &JsonCommander::executeGetdata;
|
|
|
commandsMap["head"] = &JsonCommander::executeHead;
|
|
|
+ commandsMap["deleteme"] = &JsonCommander::executeDeleteMe;
|
|
|
}
|
|
|
|
|
|
JsonCommander::~JsonCommander() {}
|
|
@@ -403,6 +404,29 @@ JsonCommander::Response JsonCommander::executeHead(const Json::Value &message) {
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
+JsonCommander::Response
|
|
|
+JsonCommander::executeDeleteMe(const Json::Value &message) {
|
|
|
+ JsonCommander::Response response;
|
|
|
+ response.json["command"] = "deleteme";
|
|
|
+
|
|
|
+ if (!message["pass"].isString()) {
|
|
|
+ response.action = send;
|
|
|
+ response.json["accept"] = false;
|
|
|
+ response.json["error"] = "incorrect deleteme command request";
|
|
|
+ } else if (UserManager::deleteUser(currentUser, message["pass"].asString())) {
|
|
|
+ // success
|
|
|
+ response.action = closeAndSend;
|
|
|
+ response.json["accept"] = true;
|
|
|
+ response.json["error"] = "";
|
|
|
+ } else {
|
|
|
+ response.action = send;
|
|
|
+ response.json["accept"] = false;
|
|
|
+ response.json["error"] = "wrong password";
|
|
|
+ }
|
|
|
+
|
|
|
+ return response;
|
|
|
+}
|
|
|
+
|
|
|
JsonCommander::Response JsonCommander::testVersion(const Json::Value &message) {
|
|
|
JsonCommander::Response response;
|
|
|
response.json["version"] = this->protocolVersion;
|
|
@@ -438,6 +462,7 @@ JsonCommander::Response JsonCommander::checkLogin(const Json::Value &message) {
|
|
|
response.action = send;
|
|
|
response.json["accept"] = true;
|
|
|
response.json["error"] = "";
|
|
|
+ currentUser = message["user"].asString();
|
|
|
} else if (!message["login"].asBool()) {
|
|
|
// add user. Check if already exists before
|
|
|
if (!UserManager::addUser(message["user"].asString(),
|
|
@@ -449,8 +474,8 @@ JsonCommander::Response JsonCommander::checkLogin(const Json::Value &message) {
|
|
|
response.action = send;
|
|
|
response.json["accept"] = true;
|
|
|
response.json["error"] = "";
|
|
|
+ currentUser = message["user"].asString();
|
|
|
}
|
|
|
-
|
|
|
} else {
|
|
|
// reject user
|
|
|
response.action = closeAndSend;
|