updated for classes and small fix web
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:
@@ -8,14 +8,14 @@ namespace AuthService
|
||||
{
|
||||
AuthService::AuthService()
|
||||
{
|
||||
this->srv.Post("/api/token", Auth::auth);
|
||||
this->srv.Post("/api/users/user", Users::get_user);
|
||||
this->srv.Post("/api/users/all", Users::get_all_users);
|
||||
this->srv.Post("/api/users/add", Users::add_user);
|
||||
this->srv.Post("/api/users/user/password/change", Users::change_password);
|
||||
this->srv.Post("/api/users/del", Users::delete_user);
|
||||
this->srv.Post("/api/access", Users::user_access);
|
||||
this->srv.Post("/api/users/user/change", Users::change_user);
|
||||
this->srv.Post("/api/token", Auth::Auth::auth);
|
||||
this->srv.Post("/api/users/user", Users::Users::get_user);
|
||||
this->srv.Post("/api/users/all", Users::Users::get_all_users);
|
||||
this->srv.Post("/api/users/add", Users::Users::add_user);
|
||||
this->srv.Post("/api/users/user/password/change", Users::Users::change_password);
|
||||
this->srv.Post("/api/users/del", Users::Users::delete_user);
|
||||
this->srv.Post("/api/access", Users::Users::user_access);
|
||||
this->srv.Post("/api/users/user/change", Users::Users::change_user);
|
||||
|
||||
this->srv.Options("/(.*)", Security::set_cors_headers);
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ namespace AuthService
|
||||
namespace Auth
|
||||
{
|
||||
// function for authorization users
|
||||
void auth(const httplib::Request& request, httplib::Response& response)
|
||||
void Auth::auth(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
|
||||
+7
-4
@@ -6,10 +6,13 @@ namespace AuthService
|
||||
{
|
||||
namespace Auth
|
||||
{
|
||||
// function for authorization users
|
||||
void auth(const httplib::Request& request, httplib::Response& response);
|
||||
class Auth {
|
||||
public:
|
||||
// function for authorization users
|
||||
static void auth(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for verify tokens
|
||||
void verify_auth(const std::string& token, httplib::Response& response);
|
||||
// function for verify tokens
|
||||
static void verify_auth(const std::string& token, httplib::Response& response);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace AuthService
|
||||
response.set_content(R"({"access":"reject"})", JSON_TYPE);
|
||||
syslog(LOG_ERR, "access rejected");
|
||||
}
|
||||
void verify_auth(const std::string& token, httplib::Response& response)
|
||||
void Auth::Auth::verify_auth(const std::string& token, httplib::Response& response)
|
||||
{
|
||||
try {
|
||||
if (!JWT::verifyJWT(token, JWT_SECRET_KEY)) {
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// function for access or reject authorization
|
||||
void user_access(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::user_access(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
response.set_content(R"({"access":"success"})", JSON_TYPE);
|
||||
syslog(LOG_INFO, "access success");
|
||||
}
|
||||
|
||||
@@ -22,14 +22,14 @@ namespace AuthService
|
||||
}
|
||||
|
||||
// function for add user
|
||||
void add_user(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::add_user(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
AuthService::Includes::check_body_empty(request, response, ADD_USER_REQUIRED_STRING);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, ADD_USER_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Includes::check_body_data(json_body, "username", response, ADD_USER_REQUIRED_STRING);
|
||||
AuthService::Includes::check_body_data(json_body, "password", response, ADD_USER_REQUIRED_STRING);
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// functtion for change password for user
|
||||
void change_password(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::change_password(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
@@ -20,7 +20,7 @@ namespace AuthService
|
||||
AuthService::Includes::check_body_data(json_body, "userid", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||
AuthService::Includes::check_body_data(json_body, "old_password", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||
AuthService::Includes::check_body_data(json_body, "new_password", response, CHANGE_PASSWORD_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
|
||||
std::string old_password;
|
||||
const std::string new_password = json_body["new_password"];
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// function for change user data
|
||||
void change_user(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::change_user(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
@@ -19,7 +19,7 @@ namespace AuthService
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, CHANGE_USER_REQUIRED_STRING);
|
||||
AuthService::Includes::check_body_data(json_body, "userid", response, CHANGE_USER_REQUIRED_STRING);
|
||||
AuthService::Includes::check_body_data(json_body, "old_password", response, CHANGE_USER_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// function for delete user
|
||||
void delete_user(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::delete_user(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
AuthService::Includes::check_body_empty(request, response, DELETE_USER_REQUIRED_STRING);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, DELETE_USER_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// function for get all users data without password
|
||||
void get_all_users(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::get_all_users(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
|
||||
@@ -10,14 +10,14 @@ namespace AuthService
|
||||
namespace Users
|
||||
{
|
||||
// function for get user data without password
|
||||
void get_user(const httplib::Request& request, httplib::Response& response)
|
||||
void Users::get_user(const httplib::Request& request, httplib::Response& response)
|
||||
{
|
||||
std::cout << GREEN << request.path << RESET << " " << request.method << std::endl;
|
||||
response.set_header("Access-Control-Allow-Origin", "*");
|
||||
AuthService::Includes::check_body_empty(request, response, ACCESS_REQUIRED_STRING);
|
||||
nlohmann::json json_body = nlohmann::json::parse(request.body);
|
||||
AuthService::Includes::check_body_data(json_body, "token", response, ACCESS_REQUIRED_STRING);
|
||||
AuthService::Auth::verify_auth(json_body["token"], response);
|
||||
AuthService::Auth::Auth::verify_auth(json_body["token"], response);
|
||||
std::string userid = JWT::get_payload(json_body["token"], JWT_SECRET_KEY)["userId"];
|
||||
if (userid.empty()) {
|
||||
response.set_content(STRING403, JSON_TYPE);
|
||||
|
||||
+17
-14
@@ -7,26 +7,29 @@ namespace AuthService
|
||||
{
|
||||
namespace Users
|
||||
{
|
||||
// function for get user data without password
|
||||
void get_user(const httplib::Request& request, httplib::Response& response);
|
||||
class Users {
|
||||
public:
|
||||
// function for get user data without password
|
||||
static void get_user(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for get all users data without password
|
||||
void get_all_users(const httplib::Request& request, httplib::Response& response);
|
||||
// function for get all users data without password
|
||||
static void get_all_users(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for access or reject authorization
|
||||
void user_access(const httplib::Request& request, httplib::Response& response);
|
||||
// function for access or reject authorization
|
||||
static void user_access(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for add user
|
||||
void add_user(const httplib::Request& request, httplib::Response& response);
|
||||
// function for add user
|
||||
static void add_user(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for delete user
|
||||
void delete_user(const httplib::Request& request, httplib::Response& response);
|
||||
// function for delete user
|
||||
static void delete_user(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for change password for user
|
||||
void change_password(const httplib::Request& request, httplib::Response& response);
|
||||
// function for change password for user
|
||||
static void change_password(const httplib::Request& request, httplib::Response& response);
|
||||
|
||||
// function for change user data
|
||||
void change_user(const httplib::Request& request, httplib::Response& response);
|
||||
// function for change user data
|
||||
static void change_user(const httplib::Request& request, httplib::Response& response);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // USERS_HPP
|
||||
|
||||
+2
-1
@@ -76,7 +76,8 @@ message.addEventListener('click', () => {
|
||||
})
|
||||
|
||||
exitbutton.addEventListener('click', () => {
|
||||
localStorage.clear()
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('userdata')
|
||||
loginform.classList.add('active')
|
||||
notification('Вы вышли', "success")
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user