updated and added more funcs to be small
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
This commit is contained in:
1 parent
55ccf5b2f6
commit
794ada3d10
11 files changed
+72
-197
No files matched your search
+4
-21
@@ -14,30 +14,13 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, AUTH_REQUIRED_STRING);
|
||||||
response.set_content(AUTH_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no body in auth request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "username", response, AUTH_REQUIRED_STRING);
|
||||||
if (json_body["username"] == nullptr) {
|
AuthService::Includes::check_body_data(json_body, "password", response, AUTH_REQUIRED_STRING);
|
||||||
response.set_content(AUTH_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no username in auth request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json_body["password"] == nullptr) {
|
|
||||||
response.set_content(AUTH_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no password in auth request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const std::string request_username = json_body["username"];
|
const std::string request_username = json_body["username"];
|
||||||
const std::string request_password = json_body["password"];
|
const std::string request_password = json_body["password"];
|
||||||
|
nlohmann::json all_users = AuthService::Includes::get_all_users_from_file();
|
||||||
std::lock_guard<std::mutex> lock(AuthService::Includes::usersfilemutex);
|
|
||||||
std::ifstream usersfile(USERS_FILE);
|
|
||||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
|
||||||
usersfile.close();
|
|
||||||
|
|
||||||
std::string userid;
|
std::string userid;
|
||||||
for (nlohmann::basic_json<> user : all_users) {
|
for (nlohmann::basic_json<> user : all_users) {
|
||||||
|
|||||||
+1
-1
@@ -10,6 +10,6 @@ namespace AuthService
|
|||||||
void auth(const httplib::Request& request, httplib::Response& response);
|
void auth(const httplib::Request& request, httplib::Response& response);
|
||||||
|
|
||||||
// function for verify tokens
|
// function for verify tokens
|
||||||
bool verify_auth(const std::string& token);
|
void verify_auth(const std::string& token, httplib::Response& response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,19 +7,27 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
namespace Auth
|
namespace Auth
|
||||||
{
|
{
|
||||||
// function for verify tokens
|
void send_reject(httplib::Response& response) {
|
||||||
bool verify_auth(const std::string& token)
|
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||||
|
syslog(LOG_ERR, "access rejected");
|
||||||
|
}
|
||||||
|
void verify_auth(const std::string& token, httplib::Response& response)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return JWT::verifyJWT(token, JWT_SECRET_KEY);
|
if (!JWT::verifyJWT(token, JWT_SECRET_KEY)) {
|
||||||
|
send_reject(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (const std::system_error& e) {
|
catch (const std::system_error& e) {
|
||||||
std::cout << "Verification error: " << e.what() << std::endl;
|
std::cout << "Verification error: " << e.what() << std::endl;
|
||||||
syslog(LOG_ERR, "token verification error");
|
syslog(LOG_ERR, "token verification error");
|
||||||
return false;
|
send_reject(response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
return false;
|
send_reject(response);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#ifndef INCLUDES_HPP
|
#ifndef INCLUDES_HPP
|
||||||
#define INCLUDES_HPP
|
#define INCLUDES_HPP
|
||||||
|
|
||||||
|
#include <json.hpp>
|
||||||
|
#include <syslog.h>
|
||||||
|
|
||||||
namespace AuthService
|
namespace AuthService
|
||||||
{
|
{
|
||||||
namespace Includes
|
namespace Includes
|
||||||
@@ -16,6 +19,27 @@ namespace AuthService
|
|||||||
#define DELETE_USER_REQUIRED_STRING R"({"required":"[token] or if you superuser [token,userid]"})"
|
#define DELETE_USER_REQUIRED_STRING R"({"required":"[token] or if you superuser [token,userid]"})"
|
||||||
#define USERS_FILE "users.json"
|
#define USERS_FILE "users.json"
|
||||||
static std::mutex usersfilemutex;
|
static std::mutex usersfilemutex;
|
||||||
|
inline void check_body_empty(const httplib::Request& request, httplib::Response& response, std::string required_string) {
|
||||||
|
if (request.body.empty()) {
|
||||||
|
response.set_content(required_string, JSON_TYPE);
|
||||||
|
syslog(LOG_ERR, "no body in request");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline void check_body_data(nlohmann::json body, std::string data, httplib::Response& response, std::string required_string) {
|
||||||
|
if (body[data] == nullptr) {
|
||||||
|
response.set_content(required_string, JSON_TYPE);
|
||||||
|
syslog(LOG_ERR, "Error request");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
inline nlohmann::json get_all_users_from_file() {
|
||||||
|
std::lock_guard<std::mutex> lock(AuthService::Includes::usersfilemutex);
|
||||||
|
std::ifstream usersfile(USERS_FILE);
|
||||||
|
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||||
|
usersfile.close();
|
||||||
|
return all_users;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // INCLUDES_HPP
|
#endif // INCLUDES_HPP
|
||||||
@@ -14,23 +14,10 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access request body is emty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no token in acces request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access rejected");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
response.set_content(R"({"access":"success"})", JSON_TYPE);
|
response.set_content(R"({"access":"success"})", JSON_TYPE);
|
||||||
syslog(LOG_INFO, "access success");
|
syslog(LOG_INFO, "access success");
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-31
@@ -26,38 +26,12 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, ADD_USER_REQUIRED_STRING);
|
||||||
response.set_content(ADD_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "add user request body is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, ADD_USER_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
response.set_content(ADD_USER_REQUIRED_STRING,
|
AuthService::Includes::check_body_data(json_body, "username", response, ADD_USER_REQUIRED_STRING);
|
||||||
JSON_TYPE);
|
AuthService::Includes::check_body_data(json_body, "password", response, ADD_USER_REQUIRED_STRING);
|
||||||
syslog(LOG_ERR, "no token in add user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in add user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json_body["username"] == nullptr) {
|
|
||||||
response.set_content(ADD_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no username in add user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json_body["password"] == nullptr) {
|
|
||||||
response.set_content(ADD_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no password in add user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||||
if (userid.empty()) {
|
if (userid.empty()) {
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
response.set_content(STRING403, JSON_TYPE);
|
||||||
|
|||||||
@@ -14,42 +14,13 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||||
response.set_content(
|
|
||||||
CHANGE_PASSWORD_REQUIRED_STRING,
|
|
||||||
JSON_TYPE
|
|
||||||
);
|
|
||||||
syslog(LOG_ERR, "body is empty in change password request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Includes::check_body_data(json_body, "userid", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||||
response.set_content(
|
AuthService::Includes::check_body_data(json_body, "old_password", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||||
CHANGE_PASSWORD_REQUIRED_STRING,
|
AuthService::Includes::check_body_data(json_body, "new_password", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||||
JSON_TYPE
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
);
|
|
||||||
syslog(LOG_ERR, "no token in change password request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((json_body["userid"] == nullptr) && (json_body["old_password"] == nullptr)) {
|
|
||||||
response.set_content(
|
|
||||||
CHANGE_PASSWORD_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no old password is change password request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (json_body["new_password"] == nullptr) {
|
|
||||||
response.set_content(CHANGE_PASSWORD_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no new password in change password request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in change password request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string old_password;
|
std::string old_password;
|
||||||
const std::string new_password = json_body["new_password"];
|
const std::string new_password = json_body["new_password"];
|
||||||
|
|||||||
@@ -14,35 +14,12 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, CHANGE_USER_REQUIRED_STRING);
|
||||||
response.set_content(
|
|
||||||
CHANGE_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "change user request body is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, CHANGE_USER_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Includes::check_body_data(json_body, "userid", response, CHANGE_USER_REQUIRED_STRING);
|
||||||
response.set_content(
|
AuthService::Includes::check_body_data(json_body, "old_password", response, CHANGE_USER_REQUIRED_STRING);
|
||||||
CHANGE_USER_REQUIRED_STRING,
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
JSON_TYPE
|
|
||||||
);
|
|
||||||
syslog(LOG_ERR, "no token in change user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((json_body["userid"] == nullptr) && (json_body["old_password"] == nullptr)) {
|
|
||||||
response.set_content(
|
|
||||||
CHANGE_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no old_password in change user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in change user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||||
if (userid.empty()) {
|
if (userid.empty()) {
|
||||||
|
|||||||
@@ -14,27 +14,10 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, DELETE_USER_REQUIRED_STRING);
|
||||||
response.set_content(
|
|
||||||
DELETE_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "delete user request body is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, DELETE_USER_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
response.set_content(
|
|
||||||
DELETE_USER_REQUIRED_STRING,
|
|
||||||
JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no token in delete user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in delete user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||||
if (userid.empty()) {
|
if (userid.empty()) {
|
||||||
|
|||||||
@@ -14,33 +14,17 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "get all users request body is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no token in get all users");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in get all user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||||
if (userid.empty()) {
|
if (userid.empty()) {
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
response.set_content(STRING403, JSON_TYPE);
|
||||||
syslog(LOG_ERR, "access reject in get all user request");
|
syslog(LOG_ERR, "access reject in get all user request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::lock_guard<std::mutex> lock(AuthService::Includes::usersfilemutex);
|
nlohmann::json all_users = AuthService::Includes::get_all_users_from_file();
|
||||||
std::ifstream usersfile(USERS_FILE);
|
|
||||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
|
||||||
usersfile.close();
|
|
||||||
nlohmann::json response_user_data = nullptr;
|
nlohmann::json response_user_data = nullptr;
|
||||||
for (nlohmann::json& user : all_users) {
|
for (nlohmann::json& user : all_users) {
|
||||||
if (user["id"] == userid) {
|
if (user["id"] == userid) {
|
||||||
|
|||||||
+4
-20
@@ -14,33 +14,17 @@ namespace AuthService
|
|||||||
{
|
{
|
||||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
if (request.body.empty()) {
|
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "get user request body is empty");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||||
|
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||||
if (json_body["token"] == nullptr) {
|
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||||
response.set_content(ACCESS_REQUIRED_STRING, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "no token in get user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!AuthService::Auth::verify_auth(json_body["token"])) {
|
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
|
||||||
syslog(LOG_ERR, "access reject in get user request");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||||
if (userid.empty()) {
|
if (userid.empty()) {
|
||||||
response.set_content(STRING403, JSON_TYPE);
|
response.set_content(STRING403, JSON_TYPE);
|
||||||
syslog(LOG_ERR, "access reject in get user request");
|
syslog(LOG_ERR, "access reject in get user request");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::lock_guard<std::mutex> lock(AuthService::Includes::usersfilemutex);
|
nlohmann::json all_users = AuthService::Includes::get_all_users_from_file();
|
||||||
std::ifstream usersfile(USERS_FILE);
|
|
||||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
|
||||||
usersfile.close();
|
|
||||||
nlohmann::json response_user_data = nullptr;
|
nlohmann::json response_user_data = nullptr;
|
||||||
for (nlohmann::json& user : all_users) {
|
for (nlohmann::json& user : all_users) {
|
||||||
if (user["id"] == userid) {
|
if (user["id"] == userid) {
|
||||||
|
|||||||
Reference in new issue
Block a user