Merge pull request 'makefile-update' (#4) from makefile-update into main
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
Reviewed-on: https://gitea.home.com:3000/TolaMironcenko/auth_service/pulls/4
This commit was merged in pull request #4.
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
CXX=g++
|
||||
CXXFLAGS=-Wall -l ssl -l crypto -I src/libs -I src/auth -I src/security -I src/users -I src
|
||||
CXXFLAGS=-Wall \
|
||||
-l ssl \
|
||||
-l crypto \
|
||||
-I src/libs \
|
||||
-I src/auth \
|
||||
-I src/security \
|
||||
-I src/users \
|
||||
-I src
|
||||
SOURCES=src/auth_service.cpp \
|
||||
src/auth/auth.cpp \
|
||||
src/auth/verify_auth.cpp \
|
||||
@@ -12,16 +19,18 @@ SOURCES=src/auth_service.cpp \
|
||||
src/users/get_all_users.cpp \
|
||||
src/users/get_user.cpp \
|
||||
src/AuthService/AuthService.cpp
|
||||
TARGET=build/auth_service
|
||||
TARGET=auth_service
|
||||
BUILD_DIR=build
|
||||
|
||||
default: all
|
||||
all: build
|
||||
.PHONY: build
|
||||
build:
|
||||
@if [ ! -d build ]; then \
|
||||
mkdir build; \
|
||||
@if [ ! -d $(BUILD_DIR) ]; then \
|
||||
mkdir $(BUILD_DIR); \
|
||||
fi
|
||||
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
|
||||
$(CXX) -o $(BUILD_DIR)/$(TARGET) $(SOURCES) $(CXXFLAGS)
|
||||
clean:
|
||||
@if [ -f $(TARGET) ]; then \
|
||||
rm -v $(TARGET); \
|
||||
@if [ -d $(BUILD_DIR) ]; then \
|
||||
rm -rv $(BUILD_DIR); \
|
||||
fi
|
||||
|
||||
+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);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void change_password(const httplib::Request& request, httplib::Response& respons
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream usersfile("users.json");
|
||||
std::ifstream usersfile(USERS_FILE);
|
||||
nlohmann::json all_users = nlohmann::json::parse(usersfile);
|
||||
usersfile.close();
|
||||
|
||||
@@ -114,7 +114,7 @@ void change_password(const httplib::Request& request, httplib::Response& respons
|
||||
syslog(LOG_ERR, "can't find this user in change password request");
|
||||
return;
|
||||
}
|
||||
std::ofstream usersfilew("users.json");
|
||||
std::ofstream usersfilew(USERS_FILE);
|
||||
usersfilew << all_users.dump(4);
|
||||
usersfilew.close();
|
||||
response.set_content(R"({"status":"ok"})", JSON_TYPE);
|
||||
|
||||
@@ -47,7 +47,7 @@ void change_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();
|
||||
|
||||
@@ -105,7 +105,7 @@ void change_user(const httplib::Request& request, httplib::Response& response)
|
||||
syslog(LOG_ERR, "can't find this user in change user request");
|
||||
return;
|
||||
}
|
||||
std::ofstream usersfilew("users.json");
|
||||
std::ofstream usersfilew(USERS_FILE);
|
||||
usersfilew << all_users.dump(4);
|
||||
usersfilew.close();
|
||||
response.set_content(R"({"status":"ok"})", JSON_TYPE);
|
||||
|
||||
@@ -39,7 +39,7 @@ void delete_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();
|
||||
|
||||
@@ -80,7 +80,7 @@ void delete_user(const httplib::Request& request, httplib::Response& response)
|
||||
syslog(LOG_ERR, "can't find this user in delete user request");
|
||||
return;
|
||||
}
|
||||
std::ofstream usersfilew("users.json");
|
||||
std::ofstream usersfilew(USERS_FILE);
|
||||
usersfilew << all_users.dump(4);
|
||||
usersfilew.close();
|
||||
response.set_content(R"({"status":"ok"})", JSON_TYPE);
|
||||
|
||||
@@ -33,7 +33,7 @@ void get_all_users(const httplib::Request& request, httplib::Response& response)
|
||||
syslog(LOG_ERR, "access reject in get all 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;
|
||||
|
||||
@@ -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