some optimization
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
This commit is contained in:
1 parent
f5b92b8e50
commit
aeefe1ea7f
5 files changed
+25
-17
No files matched your search
+3
-4
@@ -31,7 +31,7 @@ void auth(const httplib::Request& request, httplib::Response& response)
|
||||
const std::string request_username = json_body["username"];
|
||||
const std::string request_password = json_body["password"];
|
||||
|
||||
std::ifstream usersfile("users.json");
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
|
||||
@@ -59,8 +59,7 @@ void auth(const httplib::Request& request, httplib::Response& response)
|
||||
|
||||
std::string token = JWT::createJWT(headers.dump(), payload.dump(), JWT_SECRET_KEY);
|
||||
|
||||
std::stringstream response_json;
|
||||
response_json << R"({"token":")" << token.c_str() << "\"}";
|
||||
std::string response_json = R"({"token":")" + token + "\"}";
|
||||
syslog(LOG_INFO, "auth request success");
|
||||
response.set_content(response_json.str(), JSON_TYPE);
|
||||
response.set_content(response_json, JSON_TYPE);
|
||||
}
|
||||
@@ -10,5 +10,6 @@
|
||||
#define CHANGE_PASSWORD_REQUIRED_STRING R"({"required":"[token,old_password,new_password] or if you superuser [token,userid,new_password]"})"
|
||||
#define CHANGE_USER_REQUIRED_STRING R"({"required":"[token] or if you superuser [token,userid]","optional":"[username,password,is_superuser,group]"})"
|
||||
#define DELETE_USER_REQUIRED_STRING R"({"required":"[token] or if you superuser [token,userid]"})"
|
||||
#define USERS_FILE "users.json"
|
||||
|
||||
#endif // INCLUDES_HPP
|
||||
@@ -62,7 +62,7 @@ void add_user(const httplib::Request& request, httplib::Response& response)
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream usersfile("users.json");
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
|
||||
@@ -104,11 +104,10 @@ void add_user(const httplib::Request& request, httplib::Response& response)
|
||||
new_user_data << "}";
|
||||
all_users.push_back(nlohmann::json::parse(new_user_data));
|
||||
|
||||
std::ofstream usersfilew("users.json");
|
||||
std::ofstream usersfilew(USERS_FILE);
|
||||
usersfilew << all_users.dump(4);
|
||||
usersfilew.close();
|
||||
std::stringstream syslogstring;
|
||||
syslogstring << "user added [" << username << "]";
|
||||
syslog(LOG_INFO, syslogstring.str().c_str());
|
||||
std::string syslogstring = "user added [" + username + "]";
|
||||
syslog(LOG_INFO, syslogstring.c_str());
|
||||
response.set_content(R"({"status":"ok"})", JSON_TYPE);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ void get_user(const httplib::Request& request, httplib::Response& response)
|
||||
syslog(LOG_ERR, "access reject in get user request");
|
||||
return;
|
||||
}
|
||||
std::ifstream usersfile("users.json");
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
nlohmann::json response_user_data = nullptr;
|
||||
|
||||
Reference in new issue
Block a user