From 423aca9892a56e04bcdadee2939de020399dc8d4 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 30 Oct 2021 09:46:07 -0700 Subject: [PATCH] Fixing token generation. --- build | 2 +- src/AuthService.cpp | 2 +- src/framework/MicroService.h | 51 +++++++++++++++++++++++++++++++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/build b/build index 3cacc0b..da2d398 100644 --- a/build +++ b/build @@ -1 +1 @@ -12 \ No newline at end of file +14 \ No newline at end of file diff --git a/src/AuthService.cpp b/src/AuthService.cpp index 6d4008c..aef5239 100644 --- a/src/AuthService.cpp +++ b/src/AuthService.cpp @@ -143,7 +143,7 @@ namespace OpenWifi { } [[nodiscard]] std::string AuthService::GenerateTokenHMAC(const std::string & UserName, ACCESS_TYPE Type) { - std::string Identity(UserName + ":" + Poco::format("%d",(int)std::time(nullptr))); + std::string Identity(UserName + ":" + Poco::format("%d",(int)std::time(nullptr)) + ":" + std::to_string(rand())); HMAC_.update(Identity); return Poco::DigestEngine::digestToHex(HMAC_.digest()); } diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index c6f6893..59e751d 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -277,6 +277,31 @@ namespace OpenWifi::RESTAPI_utils { return OS.str(); } + template std::string to_string(const std::vector> & ObjectArray) { + Poco::JSON::Array OutputArr; + if(ObjectArray.empty()) + return "[]"; + for(auto const &i:ObjectArray) { + Poco::JSON::Array InnerArr; + for(auto const &j:i) { + if constexpr(std::is_integral::value) { + InnerArr.add(j); + } if constexpr(std::is_same_v) { + InnerArr.add(j); + } else { + InnerArr.add(j); + Poco::JSON::Object O; + j.to_json(O); + InnerArr.add(O); + } + } + OutputArr.add(InnerArr); + } + std::ostringstream OS; + Poco::JSON::Stringifier::condense(OutputArr,OS); + return OS.str(); + } + template std::string to_string(const T & Object) { Poco::JSON::Object OutputObj; Object.to_json(OutputObj); @@ -321,7 +346,6 @@ namespace OpenWifi::RESTAPI_utils { } template std::vector to_object_array(const std::string & ObjectString) { - std::vector Result; if(ObjectString.empty()) return Result; @@ -341,6 +365,31 @@ namespace OpenWifi::RESTAPI_utils { return Result; } + template std::vector> to_array_of_array_of_object(const std::string & ObjectString) { + std::vector> Result; + if(ObjectString.empty()) + return Result; + try { + Poco::JSON::Parser P1; + auto OutterArray = P1.parse(ObjectString).template extract(); + for (auto const &i : *OutterArray) { + Poco::JSON::Parser P2; + auto InnerArray = P2.parse(i).template extract(); + std::vector InnerVector; + for(auto const &j: *InnerArray) { + auto Object = j.template extract(); + T Obj; + Obj.from_json(Object); + InnerVector.push_back(Obj); + } + Result.push_back(InnerVector); + } + } catch (...) { + + } + return Result; + } + template T to_object(const std::string & ObjectString) { T Result;