added editorconfig and formated code
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
77a483a38a
commit
e5abe4bb02
18 files changed
+1636
-782
No files matched your search
@@ -0,0 +1,46 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
tab_width = 8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[DEVELOPERS]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[Config*.in*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[linux/Config.ext.in]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[Makefile*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.mk]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.patch]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[S{0..9}{0..9}*]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = tab
|
||||||
|
|
||||||
|
[*.adoc]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{c++,cc,cpp,cxx,h,h++,hh,hpp,hxx,inl,ipp,tlh,tli}]
|
||||||
|
|
||||||
|
cpp_indent_case_contents_when_block = true
|
||||||
|
cpp_new_line_before_open_brace_namespace = new_line
|
||||||
|
cpp_new_line_before_open_brace_function = new_line
|
||||||
@@ -1,16 +1,27 @@
|
|||||||
CXX=g++
|
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 src/security/cors.cpp src/users/access_request.cpp src/users/add_user.cpp src/users/change_password.cpp src/users/change_user.cpp src/users/delete_user.cpp src/users/get_all_users.cpp src/users/get_user.cpp src/AuthService/AuthService.cpp
|
SOURCES=src/auth_service.cpp \
|
||||||
TARGET=bin/auth_service
|
src/auth/auth.cpp \
|
||||||
|
src/auth/verify_auth.cpp \
|
||||||
|
src/security/cors.cpp \
|
||||||
|
src/users/access_request.cpp \
|
||||||
|
src/users/add_user.cpp \
|
||||||
|
src/users/change_password.cpp \
|
||||||
|
src/users/change_user.cpp \
|
||||||
|
src/users/delete_user.cpp \
|
||||||
|
src/users/get_all_users.cpp \
|
||||||
|
src/users/get_user.cpp \
|
||||||
|
src/AuthService/AuthService.cpp
|
||||||
|
TARGET=build/auth_service
|
||||||
default: all
|
default: all
|
||||||
all: build
|
all: build
|
||||||
|
.PHONY: build
|
||||||
build:
|
build:
|
||||||
@if [ ! -d bin ]; then \
|
@if [ ! -d build ]; then \
|
||||||
mkdir bin; \
|
mkdir build; \
|
||||||
fi
|
fi
|
||||||
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
|
$(CXX) -o $(TARGET) $(SOURCES) $(CXXFLAGS)
|
||||||
clean:
|
clean:
|
||||||
@if [ -f $(TARGET) ]; then \
|
@if [ -f $(TARGET) ]; then \
|
||||||
rm -v $(TARGET); \
|
rm -v $(TARGET); \
|
||||||
fi
|
fi
|
||||||
|
|
||||||
+1
-1
@@ -16,5 +16,5 @@ executable(
|
|||||||
'src/auth/auth.cpp',
|
'src/auth/auth.cpp',
|
||||||
'src/auth/verify_auth.cpp',
|
'src/auth/verify_auth.cpp',
|
||||||
include_directories: include_dirs,
|
include_directories: include_dirs,
|
||||||
dependencies : deps
|
dependencies: deps,
|
||||||
)
|
)
|
||||||
+2
-1
@@ -7,7 +7,8 @@
|
|||||||
#include <security/HashPassword.hpp>
|
#include <security/HashPassword.hpp>
|
||||||
|
|
||||||
// function for authorization users
|
// function for authorization users
|
||||||
void auth(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
@@ -5,10 +5,12 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// function for verify tokens
|
// function for verify tokens
|
||||||
bool verify_auth(const std::string &token) {
|
bool verify_auth(const std::string& token)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
return JWT::verifyJWT(token, JWT_SECRET_KEY);
|
return JWT::verifyJWT(token, JWT_SECRET_KEY);
|
||||||
} 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;
|
return false;
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include <AuthService/AuthService.hpp>
|
#include <AuthService/AuthService.hpp>
|
||||||
|
|
||||||
int main() {
|
int main()
|
||||||
|
{
|
||||||
AuthService auth_service;
|
AuthService auth_service;
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
return auth_service.serve("127.0.0.1", 43243);
|
return auth_service.serve("0.0.0.0", 43243);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
+1410
-697
File diff suppressed because it is too large.
Load diff
+114
-54
@@ -2976,7 +2976,8 @@ inline void replace_substring(StringType& s, const StringType& f,
|
|||||||
pos != StringType::npos; // make sure f was found
|
pos != StringType::npos; // make sure f was found
|
||||||
s.replace(pos, f.size(), t), // replace with t, and
|
s.replace(pos, f.size(), t), // replace with t, and
|
||||||
pos = s.find(f, pos + t.size())) // find next occurrence of f
|
pos = s.find(f, pos + t.size())) // find next occurrence of f
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -3473,7 +3474,8 @@ struct is_basic_json_context :
|
|||||||
std::integral_constant < bool,
|
std::integral_constant < bool,
|
||||||
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
|
is_basic_json<typename std::remove_cv<typename std::remove_pointer<BasicJsonContext>::type>::type>::value
|
||||||
|| std::is_same<BasicJsonContext, std::nullptr_t>::value >
|
|| std::is_same<BasicJsonContext, std::nullptr_t>::value >
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// json_ref helpers //
|
// json_ref helpers //
|
||||||
@@ -3602,7 +3604,8 @@ using actual_object_comparator_t = typename actual_object_comparator<BasicJsonTy
|
|||||||
// Primary template of char_traits calls std char_traits
|
// Primary template of char_traits calls std char_traits
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct char_traits : std::char_traits<T>
|
struct char_traits : std::char_traits<T>
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// Explicitly define char traits for unsigned char since it is not standard
|
// Explicitly define char traits for unsigned char since it is not standard
|
||||||
template<>
|
template<>
|
||||||
@@ -3661,7 +3664,8 @@ template<class...> struct conjunction : std::true_type { };
|
|||||||
template<class B> struct conjunction<B> : B {};
|
template<class B> struct conjunction<B> : B {};
|
||||||
template<class B, class... Bn>
|
template<class B, class... Bn>
|
||||||
struct conjunction<B, Bn...>
|
struct conjunction<B, Bn...>
|
||||||
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {};
|
: std::conditional<static_cast<bool>(B::value), conjunction<Bn...>, B>::type {
|
||||||
|
};
|
||||||
|
|
||||||
// https://en.cppreference.com/w/cpp/types/negation
|
// https://en.cppreference.com/w/cpp/types/negation
|
||||||
template<class B> struct negation : std::integral_constant < bool, !B::value > {};
|
template<class B> struct negation : std::integral_constant < bool, !B::value > {};
|
||||||
@@ -3674,19 +3678,23 @@ struct is_default_constructible : std::is_default_constructible<T> {};
|
|||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
struct is_default_constructible<std::pair<T1, T2>>
|
struct is_default_constructible<std::pair<T1, T2>>
|
||||||
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
|
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T1, typename T2>
|
template <typename T1, typename T2>
|
||||||
struct is_default_constructible<const std::pair<T1, T2>>
|
struct is_default_constructible<const std::pair<T1, T2>>
|
||||||
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {};
|
: conjunction<is_default_constructible<T1>, is_default_constructible<T2>> {
|
||||||
|
};
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
struct is_default_constructible<std::tuple<Ts...>>
|
struct is_default_constructible<std::tuple<Ts...>>
|
||||||
: conjunction<is_default_constructible<Ts>...> {};
|
: conjunction<is_default_constructible<Ts>...> {
|
||||||
|
};
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
struct is_default_constructible<const std::tuple<Ts...>>
|
struct is_default_constructible<const std::tuple<Ts...>>
|
||||||
: conjunction<is_default_constructible<Ts>...> {};
|
: conjunction<is_default_constructible<Ts>...> {
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T, typename... Args>
|
template <typename T, typename... Args>
|
||||||
struct is_constructible : std::is_constructible<T, Args...> {};
|
struct is_constructible : std::is_constructible<T, Args...> {};
|
||||||
@@ -3778,7 +3786,8 @@ struct is_compatible_object_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleObjectType>
|
template<typename BasicJsonType, typename CompatibleObjectType>
|
||||||
struct is_compatible_object_type
|
struct is_compatible_object_type
|
||||||
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {};
|
: is_compatible_object_type_impl<BasicJsonType, CompatibleObjectType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleObjectType,
|
template<typename BasicJsonType, typename ConstructibleObjectType,
|
||||||
typename = void>
|
typename = void>
|
||||||
@@ -3811,7 +3820,8 @@ struct is_constructible_object_type_impl <
|
|||||||
template<typename BasicJsonType, typename ConstructibleObjectType>
|
template<typename BasicJsonType, typename ConstructibleObjectType>
|
||||||
struct is_constructible_object_type
|
struct is_constructible_object_type
|
||||||
: is_constructible_object_type_impl<BasicJsonType,
|
: is_constructible_object_type_impl<BasicJsonType,
|
||||||
ConstructibleObjectType> {};
|
ConstructibleObjectType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleStringType>
|
template<typename BasicJsonType, typename CompatibleStringType>
|
||||||
struct is_compatible_string_type
|
struct is_compatible_string_type
|
||||||
@@ -3857,7 +3867,8 @@ struct is_compatible_array_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleArrayType>
|
template<typename BasicJsonType, typename CompatibleArrayType>
|
||||||
struct is_compatible_array_type
|
struct is_compatible_array_type
|
||||||
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {};
|
: is_compatible_array_type_impl<BasicJsonType, CompatibleArrayType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
|
template<typename BasicJsonType, typename ConstructibleArrayType, typename = void>
|
||||||
struct is_constructible_array_type_impl : std::false_type {};
|
struct is_constructible_array_type_impl : std::false_type {};
|
||||||
@@ -3901,7 +3912,8 @@ is_detected<range_value_t, ConstructibleArrayType>::value&&
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename ConstructibleArrayType>
|
template<typename BasicJsonType, typename ConstructibleArrayType>
|
||||||
struct is_constructible_array_type
|
struct is_constructible_array_type
|
||||||
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {};
|
: is_constructible_array_type_impl<BasicJsonType, ConstructibleArrayType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType,
|
||||||
typename = void>
|
typename = void>
|
||||||
@@ -3928,7 +3940,8 @@ struct is_compatible_integer_type_impl <
|
|||||||
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
template<typename RealIntegerType, typename CompatibleNumberIntegerType>
|
||||||
struct is_compatible_integer_type
|
struct is_compatible_integer_type
|
||||||
: is_compatible_integer_type_impl<RealIntegerType,
|
: is_compatible_integer_type_impl<RealIntegerType,
|
||||||
CompatibleNumberIntegerType> {};
|
CompatibleNumberIntegerType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleType, typename = void>
|
template<typename BasicJsonType, typename CompatibleType, typename = void>
|
||||||
struct is_compatible_type_impl : std::false_type {};
|
struct is_compatible_type_impl : std::false_type {};
|
||||||
@@ -3944,7 +3957,8 @@ struct is_compatible_type_impl <
|
|||||||
|
|
||||||
template<typename BasicJsonType, typename CompatibleType>
|
template<typename BasicJsonType, typename CompatibleType>
|
||||||
struct is_compatible_type
|
struct is_compatible_type
|
||||||
: is_compatible_type_impl<BasicJsonType, CompatibleType> {};
|
: is_compatible_type_impl<BasicJsonType, CompatibleType> {
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
struct is_constructible_tuple : std::false_type {};
|
struct is_constructible_tuple : std::false_type {};
|
||||||
@@ -3960,7 +3974,8 @@ struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::iterator> : st
|
|||||||
|
|
||||||
template<typename BasicJsonType>
|
template<typename BasicJsonType>
|
||||||
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
|
struct is_json_iterator_of<BasicJsonType, typename BasicJsonType::const_iterator> : std::true_type
|
||||||
{};
|
{
|
||||||
|
};
|
||||||
|
|
||||||
// checks if a given type T is a template specialization of Primary
|
// checks if a given type T is a template specialization of Primary
|
||||||
template<template <typename...> class Primary, typename T>
|
template<template <typename...> class Primary, typename T>
|
||||||
@@ -4263,7 +4278,8 @@ inline std::size_t concat_length(const StringType& str, const Args& ... rest)
|
|||||||
|
|
||||||
template<typename OutStringType>
|
template<typename OutStringType>
|
||||||
inline void concat_into(OutStringType& /*out*/)
|
inline void concat_into(OutStringType& /*out*/)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<typename StringType, typename Arg>
|
template<typename StringType, typename Arg>
|
||||||
using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg&& >()));
|
using string_can_append = decltype(std::declval<StringType&>().append(std::declval < Arg&& >()));
|
||||||
@@ -4508,7 +4524,9 @@ class parse_error : public exception
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
parse_error(int id_, std::size_t byte_, const char* what_arg)
|
parse_error(int id_, std::size_t byte_, const char* what_arg)
|
||||||
: exception(id_, what_arg), byte(byte_) {}
|
: exception(id_, what_arg), byte(byte_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
static std::string position_string(const position_t& pos)
|
static std::string position_string(const position_t& pos)
|
||||||
{
|
{
|
||||||
@@ -4532,7 +4550,9 @@ class invalid_iterator : public exception
|
|||||||
private:
|
private:
|
||||||
JSON_HEDLEY_NON_NULL(3)
|
JSON_HEDLEY_NON_NULL(3)
|
||||||
invalid_iterator(int id_, const char* what_arg)
|
invalid_iterator(int id_, const char* what_arg)
|
||||||
: exception(id_, what_arg) {}
|
: exception(id_, what_arg)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @brief exception indicating executing a member function with a wrong type
|
/// @brief exception indicating executing a member function with a wrong type
|
||||||
@@ -5211,7 +5231,8 @@ template<typename IteratorType> class iteration_proxy_value
|
|||||||
&& std::is_nothrow_default_constructible<string_type>::value)
|
&& std::is_nothrow_default_constructible<string_type>::value)
|
||||||
: anchor(std::move(it))
|
: anchor(std::move(it))
|
||||||
, array_index(array_index_)
|
, array_index(array_index_)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
iteration_proxy_value(iteration_proxy_value const&) = default;
|
iteration_proxy_value(iteration_proxy_value const&) = default;
|
||||||
iteration_proxy_value& operator=(iteration_proxy_value const&) = default;
|
iteration_proxy_value& operator=(iteration_proxy_value const&) = default;
|
||||||
@@ -5314,7 +5335,9 @@ template<typename IteratorType> class iteration_proxy
|
|||||||
|
|
||||||
/// construct iteration proxy from a container
|
/// construct iteration proxy from a container
|
||||||
explicit iteration_proxy(typename IteratorType::reference cont) noexcept
|
explicit iteration_proxy(typename IteratorType::reference cont) noexcept
|
||||||
: container(&cont) {}
|
: container(&cont)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
iteration_proxy(iteration_proxy const&) = default;
|
iteration_proxy(iteration_proxy const&) = default;
|
||||||
iteration_proxy& operator=(iteration_proxy const&) = default;
|
iteration_proxy& operator=(iteration_proxy const&) = default;
|
||||||
@@ -5369,7 +5392,8 @@ namespace std
|
|||||||
#endif
|
#endif
|
||||||
template<typename IteratorType>
|
template<typename IteratorType>
|
||||||
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
class tuple_size<::nlohmann::detail::iteration_proxy_value<IteratorType>> // NOLINT(cert-dcl58-cpp)
|
||||||
: public std::integral_constant<std::size_t, 2> {};
|
: public std::integral_constant<std::size_t, 2> {
|
||||||
|
};
|
||||||
|
|
||||||
template<std::size_t N, typename IteratorType>
|
template<std::size_t N, typename IteratorType>
|
||||||
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
|
class tuple_element<N, ::nlohmann::detail::iteration_proxy_value<IteratorType >> // NOLINT(cert-dcl58-cpp)
|
||||||
@@ -5897,31 +5921,36 @@ class byte_container_with_subtype : public BinaryType
|
|||||||
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
||||||
byte_container_with_subtype() noexcept(noexcept(container_type()))
|
byte_container_with_subtype() noexcept(noexcept(container_type()))
|
||||||
: container_type()
|
: container_type()
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
||||||
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
|
byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b)))
|
||||||
: container_type(b)
|
: container_type(b)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
||||||
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
|
byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b))))
|
||||||
: container_type(std::move(b))
|
: container_type(std::move(b))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
||||||
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
|
byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b)))
|
||||||
: container_type(b)
|
: container_type(b)
|
||||||
, m_subtype(subtype_)
|
, m_subtype(subtype_)
|
||||||
, m_has_subtype(true)
|
, m_has_subtype(true)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/
|
||||||
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
|
byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b))))
|
||||||
: container_type(std::move(b))
|
: container_type(std::move(b))
|
||||||
, m_subtype(subtype_)
|
, m_subtype(subtype_)
|
||||||
, m_has_subtype(true)
|
, m_has_subtype(true)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const byte_container_with_subtype& rhs) const
|
bool operator==(const byte_container_with_subtype& rhs) const
|
||||||
{
|
{
|
||||||
@@ -6240,7 +6269,8 @@ class input_stream_adapter
|
|||||||
|
|
||||||
explicit input_stream_adapter(std::istream& i)
|
explicit input_stream_adapter(std::istream& i)
|
||||||
: is(&i), sb(i.rdbuf())
|
: is(&i), sb(i.rdbuf())
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// delete because of pointer members
|
// delete because of pointer members
|
||||||
input_stream_adapter(const input_stream_adapter&) = delete;
|
input_stream_adapter(const input_stream_adapter&) = delete;
|
||||||
@@ -6285,7 +6315,8 @@ class iterator_input_adapter
|
|||||||
|
|
||||||
iterator_input_adapter(IteratorType first, IteratorType last)
|
iterator_input_adapter(IteratorType first, IteratorType last)
|
||||||
: current(std::move(first)), end(std::move(last))
|
: current(std::move(first)), end(std::move(last))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
typename char_traits<char_type>::int_type get_character()
|
typename char_traits<char_type>::int_type get_character()
|
||||||
{
|
{
|
||||||
@@ -6443,7 +6474,9 @@ class wide_string_input_adapter
|
|||||||
using char_type = char;
|
using char_type = char;
|
||||||
|
|
||||||
wide_string_input_adapter(BaseInputAdapter base)
|
wide_string_input_adapter(BaseInputAdapter base)
|
||||||
: base_adapter(base) {}
|
: base_adapter(base)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
typename std::char_traits<char>::int_type get_character() noexcept
|
typename std::char_traits<char>::int_type get_character() noexcept
|
||||||
{
|
{
|
||||||
@@ -6612,14 +6645,18 @@ class span_input_adapter
|
|||||||
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
sizeof(typename std::remove_pointer<CharT>::type) == 1,
|
||||||
int >::type = 0 >
|
int >::type = 0 >
|
||||||
span_input_adapter(CharT b, std::size_t l)
|
span_input_adapter(CharT b, std::size_t l)
|
||||||
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l) {}
|
: ia(reinterpret_cast<const char*>(b), reinterpret_cast<const char*>(b) + l)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template<class IteratorType,
|
template<class IteratorType,
|
||||||
typename std::enable_if<
|
typename std::enable_if<
|
||||||
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
|
std::is_same<typename iterator_traits<IteratorType>::iterator_category, std::random_access_iterator_tag>::value,
|
||||||
int>::type = 0>
|
int>::type = 0>
|
||||||
span_input_adapter(IteratorType first, IteratorType last)
|
span_input_adapter(IteratorType first, IteratorType last)
|
||||||
: ia(input_adapter(first, last)) {}
|
: ia(input_adapter(first, last))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
contiguous_bytes_input_adapter&& get()
|
contiguous_bytes_input_adapter&& get()
|
||||||
{
|
{
|
||||||
@@ -6813,7 +6850,8 @@ class json_sax_dom_parser
|
|||||||
*/
|
*/
|
||||||
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
|
explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true)
|
||||||
: root(r), allow_exceptions(allow_exceptions_)
|
: root(r), allow_exceptions(allow_exceptions_)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// make class move-only
|
// make class move-only
|
||||||
json_sax_dom_parser(const json_sax_dom_parser&) = delete;
|
json_sax_dom_parser(const json_sax_dom_parser&) = delete;
|
||||||
@@ -7497,7 +7535,8 @@ class lexer : public lexer_base<BasicJsonType>
|
|||||||
: ia(std::move(adapter))
|
: ia(std::move(adapter))
|
||||||
, ignore_comments(ignore_comments_)
|
, ignore_comments(ignore_comments_)
|
||||||
, decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
|
, decimal_point_char(static_cast<char_int_type>(get_decimal_point()))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// delete because of pointer members
|
// delete because of pointer members
|
||||||
lexer(const lexer&) = delete;
|
lexer(const lexer&) = delete;
|
||||||
@@ -8875,8 +8914,7 @@ scan_number_done:
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
}
|
} while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
|
||||||
while (current == ' ' || current == '\t' || current == '\n' || current == '\r');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
token_type scan()
|
token_type scan()
|
||||||
@@ -11908,8 +11946,7 @@ class binary_reader
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
get();
|
get();
|
||||||
}
|
} while (current == 'N');
|
||||||
while (current == 'N');
|
|
||||||
|
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
@@ -13018,7 +13055,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
*/
|
*/
|
||||||
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
|
iter_impl(const iter_impl<const BasicJsonType>& other) noexcept
|
||||||
: m_object(other.m_object), m_it(other.m_it)
|
: m_object(other.m_object), m_it(other.m_it)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief converting assignment
|
@brief converting assignment
|
||||||
@@ -13043,7 +13081,8 @@ class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-speci
|
|||||||
*/
|
*/
|
||||||
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
|
iter_impl(const iter_impl<typename std::remove_const<BasicJsonType>::type>& other) noexcept
|
||||||
: m_object(other.m_object), m_it(other.m_it)
|
: m_object(other.m_object), m_it(other.m_it)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@brief converting assignment
|
@brief converting assignment
|
||||||
@@ -13677,7 +13716,9 @@ class json_reverse_iterator : public std::reverse_iterator<Base>
|
|||||||
|
|
||||||
/// create reverse iterator from iterator
|
/// create reverse iterator from iterator
|
||||||
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
|
explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept
|
||||||
: base_iterator(it) {}
|
: base_iterator(it)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// create reverse iterator from base class
|
/// create reverse iterator from base class
|
||||||
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
|
explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {}
|
||||||
@@ -13867,7 +13908,8 @@ class json_pointer
|
|||||||
/// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/
|
/// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/
|
||||||
explicit json_pointer(const string_t& s = "")
|
explicit json_pointer(const string_t& s = "")
|
||||||
: reference_tokens(split(s))
|
: reference_tokens(split(s))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/// @brief return a string representation of the JSON pointer
|
/// @brief return a string representation of the JSON pointer
|
||||||
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/
|
/// @sa https://json.nlohmann.me/api/json_pointer/to_string/
|
||||||
@@ -14824,22 +14866,26 @@ class json_ref
|
|||||||
|
|
||||||
json_ref(value_type&& value)
|
json_ref(value_type&& value)
|
||||||
: owned_value(std::move(value))
|
: owned_value(std::move(value))
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
json_ref(const value_type& value)
|
json_ref(const value_type& value)
|
||||||
: value_ref(&value)
|
: value_ref(&value)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
json_ref(std::initializer_list<json_ref> init)
|
json_ref(std::initializer_list<json_ref> init)
|
||||||
: owned_value(init)
|
: owned_value(init)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template <
|
template <
|
||||||
class... Args,
|
class... Args,
|
||||||
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
|
enable_if_t<std::is_constructible<value_type, Args...>::value, int> = 0 >
|
||||||
json_ref(Args && ... args)
|
json_ref(Args && ... args)
|
||||||
: owned_value(std::forward<Args>(args)...)
|
: owned_value(std::forward<Args>(args)...)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// class should be movable only
|
// class should be movable only
|
||||||
json_ref(json_ref&&) noexcept = default;
|
json_ref(json_ref&&) noexcept = default;
|
||||||
@@ -14966,7 +15012,8 @@ class output_vector_adapter : public output_adapter_protocol<CharType>
|
|||||||
public:
|
public:
|
||||||
explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
|
explicit output_vector_adapter(std::vector<CharType, AllocatorType>& vec) noexcept
|
||||||
: v(vec)
|
: v(vec)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void write_character(CharType c) override
|
void write_character(CharType c) override
|
||||||
{
|
{
|
||||||
@@ -14991,7 +15038,8 @@ class output_stream_adapter : public output_adapter_protocol<CharType>
|
|||||||
public:
|
public:
|
||||||
explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
|
explicit output_stream_adapter(std::basic_ostream<CharType>& s) noexcept
|
||||||
: stream(s)
|
: stream(s)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void write_character(CharType c) override
|
void write_character(CharType c) override
|
||||||
{
|
{
|
||||||
@@ -15016,7 +15064,8 @@ class output_string_adapter : public output_adapter_protocol<CharType>
|
|||||||
public:
|
public:
|
||||||
explicit output_string_adapter(StringType& s) noexcept
|
explicit output_string_adapter(StringType& s) noexcept
|
||||||
: str(s)
|
: str(s)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void write_character(CharType c) override
|
void write_character(CharType c) override
|
||||||
{
|
{
|
||||||
@@ -15039,15 +15088,21 @@ class output_adapter
|
|||||||
public:
|
public:
|
||||||
template<typename AllocatorType = std::allocator<CharType>>
|
template<typename AllocatorType = std::allocator<CharType>>
|
||||||
output_adapter(std::vector<CharType, AllocatorType>& vec)
|
output_adapter(std::vector<CharType, AllocatorType>& vec)
|
||||||
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec)) {}
|
: oa(std::make_shared<output_vector_adapter<CharType, AllocatorType>>(vec))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef JSON_NO_IO
|
#ifndef JSON_NO_IO
|
||||||
output_adapter(std::basic_ostream<CharType>& s)
|
output_adapter(std::basic_ostream<CharType>& s)
|
||||||
: oa(std::make_shared<output_stream_adapter<CharType>>(s)) {}
|
: oa(std::make_shared<output_stream_adapter<CharType>>(s))
|
||||||
|
{
|
||||||
|
}
|
||||||
#endif // JSON_NO_IO
|
#endif // JSON_NO_IO
|
||||||
|
|
||||||
output_adapter(StringType& s)
|
output_adapter(StringType& s)
|
||||||
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s)) {}
|
: oa(std::make_shared<output_string_adapter<CharType, StringType>>(s))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
operator output_adapter_t<CharType>()
|
operator output_adapter_t<CharType>()
|
||||||
{
|
{
|
||||||
@@ -18082,7 +18137,8 @@ class serializer
|
|||||||
, indent_char(ichar)
|
, indent_char(ichar)
|
||||||
, indent_string(512, indent_char)
|
, indent_string(512, indent_char)
|
||||||
, error_handler(error_handler_)
|
, error_handler(error_handler_)
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// delete because of pointer members
|
// delete because of pointer members
|
||||||
serializer(const serializer&) = delete;
|
serializer(const serializer&) = delete;
|
||||||
@@ -19052,9 +19108,13 @@ template <class Key, class T, class IgnoredLess = std::less<Key>,
|
|||||||
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{ alloc } {}
|
explicit ordered_map(const Allocator& alloc) noexcept(noexcept(Container(alloc))) : Container{ alloc } {}
|
||||||
template <class It>
|
template <class It>
|
||||||
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
ordered_map(It first, It last, const Allocator& alloc = Allocator())
|
||||||
: Container{first, last, alloc} {}
|
: Container{ first, last, alloc }
|
||||||
|
{
|
||||||
|
}
|
||||||
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
|
ordered_map(std::initializer_list<value_type> init, const Allocator& alloc = Allocator())
|
||||||
: Container{init, alloc} {}
|
: Container{ init, alloc }
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
std::pair<iterator, bool> emplace(const key_type& key, T&& t)
|
||||||
{
|
{
|
||||||
|
|||||||
+16
-8
@@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
#define JWT_DEFAULT_SECRET "secret"
|
#define JWT_DEFAULT_SECRET "secret"
|
||||||
|
|
||||||
namespace JWT {
|
namespace JWT
|
||||||
|
{
|
||||||
inline std::string base64_encode(const unsigned char* input, int length);
|
inline std::string base64_encode(const unsigned char* input, int length);
|
||||||
inline std::string base64_decode(const std::string& in);
|
inline std::string base64_decode(const std::string& in);
|
||||||
inline std::string createJWT(const std::string& header_json, const std::string& payload_json, const std::string& secret);
|
inline std::string createJWT(const std::string& header_json, const std::string& payload_json, const std::string& secret);
|
||||||
@@ -23,7 +24,8 @@ namespace JWT {
|
|||||||
inline nlohmann::json get_payload(std::string token, std::string secret);
|
inline nlohmann::json get_payload(std::string token, std::string secret);
|
||||||
inline nlohmann::json get_header(std::string token, std::string secret);
|
inline nlohmann::json get_header(std::string token, std::string secret);
|
||||||
// Function to Base64 Encode
|
// Function to Base64 Encode
|
||||||
inline std::string base64_encode(const unsigned char *input, int length) {
|
inline std::string base64_encode(const unsigned char* input, int length)
|
||||||
|
{
|
||||||
BIO* bio, * b64;
|
BIO* bio, * b64;
|
||||||
BUF_MEM* bufferPtr;
|
BUF_MEM* bufferPtr;
|
||||||
|
|
||||||
@@ -40,7 +42,8 @@ namespace JWT {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string base64_decode(const std::string &in) {
|
inline std::string base64_decode(const std::string& in)
|
||||||
|
{
|
||||||
BIO* bio, * b64;
|
BIO* bio, * b64;
|
||||||
BUF_MEM* bufferPtr;
|
BUF_MEM* bufferPtr;
|
||||||
|
|
||||||
@@ -63,7 +66,8 @@ namespace JWT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Function to encode JWT
|
// Function to encode JWT
|
||||||
inline std::string createJWT(const std::string &header_json, const std::string &payload_json, const std::string &secret) {
|
inline std::string createJWT(const std::string& header_json, const std::string& payload_json, const std::string& secret)
|
||||||
|
{
|
||||||
// Base64 URL Encode the header
|
// Base64 URL Encode the header
|
||||||
auto encodedHeader = base64_encode(reinterpret_cast<const unsigned char*>(header_json.c_str()), header_json.length());
|
auto encodedHeader = base64_encode(reinterpret_cast<const unsigned char*>(header_json.c_str()), header_json.length());
|
||||||
// Base64 URL Encode the payload
|
// Base64 URL Encode the payload
|
||||||
@@ -89,7 +93,8 @@ namespace JWT {
|
|||||||
return jwt;
|
return jwt;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string hmacSha256(const std::string &key, const std::string &data) {
|
inline std::string hmacSha256(const std::string& key, const std::string& data)
|
||||||
|
{
|
||||||
unsigned char hash[EVP_MAX_MD_SIZE];
|
unsigned char hash[EVP_MAX_MD_SIZE];
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
|
|
||||||
@@ -100,7 +105,8 @@ namespace JWT {
|
|||||||
return std::string(reinterpret_cast<char*>(hash), length);
|
return std::string(reinterpret_cast<char*>(hash), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool verifyJWT(const std::string &token, const std::string &secret) {
|
inline bool verifyJWT(const std::string& token, const std::string& secret)
|
||||||
|
{
|
||||||
// Split the token into its three parts
|
// Split the token into its three parts
|
||||||
size_t pos1 = token.find('.');
|
size_t pos1 = token.find('.');
|
||||||
size_t pos2 = token.find('.', pos1 + 1);
|
size_t pos2 = token.find('.', pos1 + 1);
|
||||||
@@ -151,7 +157,8 @@ namespace JWT {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nlohmann::json get_payload(std::string token, std::string secret) {
|
inline nlohmann::json get_payload(std::string token, std::string secret)
|
||||||
|
{
|
||||||
size_t pos1 = token.find('.');
|
size_t pos1 = token.find('.');
|
||||||
size_t pos2 = token.find('.', pos1 + 1);
|
size_t pos2 = token.find('.', pos1 + 1);
|
||||||
|
|
||||||
@@ -167,7 +174,8 @@ namespace JWT {
|
|||||||
return jsonPayload;
|
return jsonPayload;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline nlohmann::json get_header(std::string token, std::string secret) {
|
inline nlohmann::json get_header(std::string token, std::string secret)
|
||||||
|
{
|
||||||
size_t pos1 = token.find('.');
|
size_t pos1 = token.find('.');
|
||||||
size_t pos2 = token.find('.', pos1 + 1);
|
size_t pos2 = token.find('.', pos1 + 1);
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
// funcion for hashing password using sha256
|
// funcion for hashing password using sha256
|
||||||
std::string hashPassword(const std::string &password) {
|
std::string hashPassword(const std::string& password)
|
||||||
|
{
|
||||||
unsigned char hash[SHA256_DIGEST_LENGTH];
|
unsigned char hash[SHA256_DIGEST_LENGTH];
|
||||||
|
|
||||||
// calculating hash
|
// calculating hash
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#include <security/cors.hpp>
|
#include <security/cors.hpp>
|
||||||
#include <colors.h>
|
#include <colors.h>
|
||||||
|
|
||||||
void set_cors_headers(const httplib::Request &request, httplib::Response &response) {
|
void set_cors_headers(const httplib::Request& request, httplib::Response& response)
|
||||||
|
{
|
||||||
std::cout << GREEN << request.path << " " << std::endl;
|
std::cout << GREEN << request.path << " " << std::endl;
|
||||||
response.set_header("Access-Control-Allow-Origin", "*");
|
response.set_header("Access-Control-Allow-Origin", "*");
|
||||||
response.set_header("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
|
response.set_header("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <json.hpp>
|
#include <json.hpp>
|
||||||
|
|
||||||
// function for access or reject authorization
|
// function for access or reject authorization
|
||||||
void user_access(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
#define ALPHABET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
#define ALPHABET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||||
|
|
||||||
// function for generate random string
|
// function for generate random string
|
||||||
std::string get_random_string(const char *alphabet, int quantity) {
|
std::string get_random_string(const char* alphabet, int quantity)
|
||||||
|
{
|
||||||
srand(time(nullptr));
|
srand(time(nullptr));
|
||||||
std::string str;
|
std::string str;
|
||||||
for (int i = 0; i < quantity; i++) {
|
for (int i = 0; i < quantity; i++) {
|
||||||
@@ -18,7 +19,8 @@ std::string get_random_string(const char *alphabet, int quantity) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// function for add user
|
// function for add user
|
||||||
void add_user(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// functtion for change password for user
|
// functtion for change password for user
|
||||||
void change_password(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
@@ -95,7 +96,8 @@ void change_password(const httplib::Request &request, httplib::Response &respons
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (nlohmann::basic_json<>& all_user : all_users) {
|
for (nlohmann::basic_json<>& all_user : all_users) {
|
||||||
if ((all_user["id"] == changepassuserid) && (all_user["password"] == old_password)) {
|
if ((all_user["id"] == changepassuserid) && (all_user["password"] == old_password)) {
|
||||||
all_user["password"] = new_password;
|
all_user["password"] = new_password;
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// function for change user data
|
// function for change user data
|
||||||
void change_user(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
@@ -86,7 +87,8 @@ void change_user(const httplib::Request &request, httplib::Response &response) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
for (nlohmann::basic_json<>& all_user : all_users) {
|
for (nlohmann::basic_json<>& all_user : all_users) {
|
||||||
if ((all_user["id"] == changeusruserid)) {
|
if ((all_user["id"] == changeusruserid)) {
|
||||||
if (json_body["username"] != nullptr) { all_user["username"] = json_body["username"]; }
|
if (json_body["username"] != nullptr) { all_user["username"] = json_body["username"]; }
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// function for delete user
|
// function for delete user
|
||||||
void delete_user(const httplib::Request &request, httplib::Response &response) {
|
void 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// 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 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
|
||||||
// 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 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", "*");
|
||||||
if (request.body.empty()) {
|
if (request.body.empty()) {
|
||||||
|
|||||||
Reference in new issue
Block a user