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