added color output in terminal

This commit is contained in:
wt committed 2024-05-30 15:43:37 +07:00
1 parent e7ca69aff1
commit ad94b4d194
11 files changed
+100 -1

No files matched your search

+2
View File
@@ -1,7 +1,9 @@
#include "auth.hpp"
#include "../colors.h"
// function for authorization users
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[username,password]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);
+4 -1
View File
@@ -6,6 +6,7 @@
#include "auth/auth.hpp"
#include "users/users.hpp"
#include "colors.h"
#define CORS_ENABLE
@@ -28,7 +29,9 @@ int main() {
srv.set_mount_point("/admin", "../src/web");
srv.set_mount_point("/js", "../src/web/js");
srv.set_mount_point("/css", "../src/web/css");
std::cout << GREEN << "Starting" << RESET << " server on [ " << YELLOW \
<< "localhost" << RESET << ":" << CYAN << "43243" << RESET << " ]" << std::endl;
srv.listen("localhost", 43243);
return 0;
}
+77
View File
@@ -0,0 +1,77 @@
#ifndef C_COLORS_H
#define C_COLORS_H
// reset
#define RESET "\033[0m"
// regular colrs
#define GREEN "\033[0;32m" // GREEN
#define BLUE "\033[0;34m" // BLUE
#define YELLOW "\033[1;33m" // YELLOW
#define RED "\033[0;31m" // RED
#define BLACK "\033[0;30m" // BLACK
#define PURPLE "\033[0;35m" // PURPLE
#define CYAN "\033[0;36m" // CYAN
#define WHITE "\033[0;37m" // WHITE
// bold
#define BBLACK "\033[1;30m" // BLACK
#define BRED "\033[1;31m" // RED
#define BGREEN "\033[1;32m" // GREEN
#define BYELLOW "\033[1;33m" // YELLOW
#define BBLUE "\033[1;34m" // BLUE
#define BPURPLE "\033[1;35m" // PURPLE
#define BCYAN "\033[1;36m" // CYAN
#define BWHITE "\033[1;37m" // WHITE
// Underline
#define UBLACK "\033[4;30m" // BLACK
#define URED "\033[4;31m" // RED
#define UGREEN "\033[4;32m" // GREEN
#define UYELLOW "\033[4;33m" // YELLOW
#define UBLUE "\033[4;34m" // BLUE
#define UPURPLE "\033[4;35m" // PURPLE
#define UCYAN "\033[4;36m" // CYAN
#define UWHITE "\033[4;37m" // WHITE
// Background
#define ON_BLACK "\033[40m" // BLACK
#define ON_RED "\033[41m" // RED
#define ON_GREEN "\033[42m" // GREEN
#define ON_YELLOW "\033[43m" // YELLOW
#define ON_BLUE "\033[44m" // BLUE
#define ON_PURPLE "\033[45m" // PURPLE
#define ON_CYAN "\033[46m" // CYAN
#define ON_WHITE "\033[47m" // WHITE
// High Intensity
#define IBLACK "\033[0;90m" // BLACK
#define IRED "\033[0;91m" // RED
#define IGREEN "\033[0;92m" // GREEN
#define IYELLOW "\033[0;93m" // YELLOW
#define IBLUE "\033[0;94m" // BLUE
#define IPURPLE "\033[0;95m" // PURPLE
#define ICYAN "\033[0;96m" // CYAN
#define IWHITE "\033[0;97m" // WHITE
// Bold High Intensity
#define BIBLACK "\033[1;90m" // BLACK
#define BIRED "\033[1;91m" // RED
#define BIGREEN "\033[1;92m" // GREEN
#define BIYELLOW "\033[1;93m" // YELLOW
#define BIBLUE "\033[1;94m" // BLUE
#define BIPURPLE "\033[1;95m" // PURPLE
#define BICYAN "\033[1;96m" // CYAN
#define BIWHITE "\033[1;97m" // WHITE
// High Intensity backgrounds
#define ON_IBLACK "\033[0;100m" // BLACK
#define ON_IRED "\033[0;101m" // RED
#define ON_IGREEN "\033[0;102m" // GREEN
#define ON_IYELLOW "\033[0;103m" // YELLOW
#define ON_IBLUE "\033[0;104m" // BLUE
#define ON_IPURPLE "\033[0;105m" // PURPLE
#define ON_ICYAN "\033[0;106m" // CYAN
#define ON_IWHITE "\033[0;107m" // WHITE
#endif // C_COLORS_H
+2
View File
@@ -1,6 +1,8 @@
#include "cors.hpp"
#include "../colors.h"
void set_cors_headers(const httplib::Request& request, httplib::Response& response) {
std::cout << GREEN << request.path << " " << std::endl;
response.set_header("Access-Control-Allow-Origin", "*");
response.set_header("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
response.set_header("Access-Control-Allow-Headers", "Authorization,X-Custom,Content-Type");
+2
View File
@@ -1,7 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// function for access or reject authorization
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[token]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);
+2
View File
@@ -1,4 +1,5 @@
#include "users.hpp"
#include "../colors.h"
#define ALPHABET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
@@ -14,6 +15,7 @@ std::string get_random_string(const char *alphabet, int quantity) {
// function for add user
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[token,username,password]\",\"optional\":\"[group,is_superuser]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);
+2
View File
@@ -1,7 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// functtion for change password for user
void 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", "*");
if (request.body == "") {response.set_content(
"{\"required\":\"[token,old_password,new_password] or if you superuser [token,userid,new_password]\"}",
+3
View File
@@ -1,6 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// function for change user data
void 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", "*");
if (request.body == "") {response.set_content(
"{\"required\":\"[token] or if you superuser [token,userid]\",\"optional\":\"[username,password,is_superuser,group]\"}",
+2
View File
@@ -1,7 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// function for delete user
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[token] or if you superuser [token,userid]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);
+2
View File
@@ -1,7 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// function for get all users data without password
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[token]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);
+2
View File
@@ -1,7 +1,9 @@
#include "users.hpp"
#include "../colors.h"
// function for get user data without password
void 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", "*");
if (request.body == "") {response.set_content("{\"required\":\"[token]\"}", "application/json");return;}
nlohmann::json json_body = nlohmann::json::parse(request.body);