mirror of
https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
synced 2025-11-01 19:27:59 +00:00
Moving ActionLinks into ORM
This commit is contained in:
@@ -91,7 +91,6 @@ add_executable( owsec
|
||||
src/RESTAPI/RESTAPI_email_handler.cpp src/RESTAPI/RESTAPI_email_handler.h
|
||||
src/RESTAPI/RESTAPI_sms_handler.cpp src/RESTAPI/RESTAPI_sms_handler.h
|
||||
src/storage/storage_avatar.cpp src/storage/storage_avatar.h
|
||||
src/storage/storage_actionLinks.cpp src/storage/storage_actionLinks.h
|
||||
src/storage/storage_tables.cpp
|
||||
src/RESTAPI/RESTAPI_suboauth2_handler.h src/RESTAPI/RESTAPI_suboauth2_handler.cpp
|
||||
src/RESTAPI/RESTAPI_subuser_handler.h src/RESTAPI/RESTAPI_subuser_handler.cpp
|
||||
@@ -112,7 +111,7 @@ add_executable( owsec
|
||||
src/framework/OpenWifiTypes.h
|
||||
src/RESTAPI/RESTAPI_submfa_handler.cpp src/RESTAPI/RESTAPI_submfa_handler.h
|
||||
src/storage/orm_users.cpp src/storage/orm_users.h
|
||||
src/storage/orm_tokens.cpp src/storage/orm_tokens.h src/storage/orm_preferences.cpp src/storage/orm_preferences.h)
|
||||
src/storage/orm_tokens.cpp src/storage/orm_tokens.h src/storage/orm_preferences.cpp src/storage/orm_preferences.h src/storage/orm_actionLinks.cpp src/storage/orm_actionLinks.h)
|
||||
|
||||
if(NOT SMALL_BUILD)
|
||||
target_link_libraries(owsec PUBLIC
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace OpenWifi {
|
||||
std::vector<SecurityObjects::ActionLink> Links;
|
||||
{
|
||||
std::lock_guard G(Mutex_);
|
||||
StorageService()->GetActions(Links);
|
||||
StorageService()->ActionLinksDB().GetActions(Links);
|
||||
}
|
||||
|
||||
if(Links.empty())
|
||||
@@ -45,11 +45,11 @@ namespace OpenWifi {
|
||||
SecurityObjects::UserInfo UInfo;
|
||||
if((i.action==OpenWifi::SecurityObjects::LinkActions::FORGOT_PASSWORD ||
|
||||
i.action==OpenWifi::SecurityObjects::LinkActions::VERIFY_EMAIL) && !StorageService()->UserDB().GetUserById(i.userId,UInfo)) {
|
||||
StorageService()->CancelAction(i.id);
|
||||
StorageService()->ActionLinksDB().CancelAction(i.id);
|
||||
continue;
|
||||
} else if(( i.action==OpenWifi::SecurityObjects::LinkActions::SUB_FORGOT_PASSWORD ||
|
||||
i.action==OpenWifi::SecurityObjects::LinkActions::SUB_VERIFY_EMAIL) && !StorageService()->SubDB().GetUserById(i.userId,UInfo)) {
|
||||
StorageService()->CancelAction(i.id);
|
||||
StorageService()->ActionLinksDB().CancelAction(i.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace OpenWifi {
|
||||
if(AuthService::SendEmailToUser(i.id, UInfo.email, AuthService::FORGOT_PASSWORD)) {
|
||||
Logger().information(Poco::format("Send password reset link to %s",UInfo.email));
|
||||
}
|
||||
StorageService()->SentAction(i.id);
|
||||
StorageService()->ActionLinksDB().SentAction(i.id);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -66,7 +66,7 @@ namespace OpenWifi {
|
||||
if(AuthService::SendEmailToUser(i.id, UInfo.email, AuthService::EMAIL_VERIFICATION)) {
|
||||
Logger().information(Poco::format("Send email verification link to %s",UInfo.email));
|
||||
}
|
||||
StorageService()->SentAction(i.id);
|
||||
StorageService()->ActionLinksDB().SentAction(i.id);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace OpenWifi {
|
||||
if(AuthService::SendEmailToSubUser(i.id, UInfo.email, AuthService::FORGOT_PASSWORD)) {
|
||||
Logger().information(Poco::format("Send subscriber password reset link to %s",UInfo.email));
|
||||
}
|
||||
StorageService()->SentAction(i.id);
|
||||
StorageService()->ActionLinksDB().SentAction(i.id);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -82,12 +82,12 @@ namespace OpenWifi {
|
||||
if(AuthService::SendEmailToSubUser(i.id, UInfo.email, AuthService::EMAIL_VERIFICATION)) {
|
||||
Logger().information(Poco::format("Send subscriber email verification link to %s",UInfo.email));
|
||||
}
|
||||
StorageService()->SentAction(i.id);
|
||||
StorageService()->ActionLinksDB().SentAction(i.id);
|
||||
}
|
||||
break;
|
||||
|
||||
default: {
|
||||
StorageService()->SentAction(i.id);
|
||||
StorageService()->ActionLinksDB().SentAction(i.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +624,7 @@ namespace OpenWifi {
|
||||
A.id = MicroService::CreateUUID();
|
||||
A.created = std::time(nullptr);
|
||||
A.expires = A.created + 24*60*60;
|
||||
StorageService()->CreateAction(A);
|
||||
StorageService()->ActionLinksDB().CreateAction(A);
|
||||
UInfo.waitingForEmailCheck = true;
|
||||
return true;
|
||||
}
|
||||
@@ -637,7 +637,7 @@ namespace OpenWifi {
|
||||
A.id = MicroService::CreateUUID();
|
||||
A.created = std::time(nullptr);
|
||||
A.expires = A.created + 24*60*60;
|
||||
StorageService()->CreateAction(A);
|
||||
StorageService()->ActionLinksDB().CreateAction(A);
|
||||
UInfo.waitingForEmailCheck = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace OpenWifi {
|
||||
auto Id = GetParameter("id","");
|
||||
|
||||
SecurityObjects::ActionLink Link;
|
||||
if(!StorageService()->GetActionLink(Id,Link))
|
||||
if(!StorageService()->ActionLinksDB().GetActionLink(Id,Link))
|
||||
return DoReturnA404();
|
||||
|
||||
if(Action=="password_reset")
|
||||
@@ -58,11 +58,11 @@ namespace OpenWifi {
|
||||
auto Now = std::time(nullptr);
|
||||
|
||||
SecurityObjects::ActionLink Link;
|
||||
if(!StorageService()->GetActionLink(Id,Link))
|
||||
if(!StorageService()->ActionLinksDB().GetActionLink(Id,Link))
|
||||
return DoReturnA404();
|
||||
|
||||
if(Now > Link.expires) {
|
||||
StorageService()->CancelAction(Id);
|
||||
StorageService()->ActionLinksDB().CancelAction(Id);
|
||||
return DoReturnA404();
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace OpenWifi {
|
||||
Types::StringPairVec FormVars{ {"UUID", Id},
|
||||
{"USERNAME", UInfo.email},
|
||||
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
|
||||
StorageService()->CompleteAction(Id);
|
||||
StorageService()->ActionLinksDB().CompleteAction(Id);
|
||||
SendHTMLFileBack(FormFile,FormVars);
|
||||
} else {
|
||||
DoReturnA404();
|
||||
@@ -113,7 +113,7 @@ namespace OpenWifi {
|
||||
auto Now = std::time(nullptr);
|
||||
|
||||
if(Now > Link.expires) {
|
||||
StorageService()->CancelAction(Link.id);
|
||||
StorageService()->ActionLinksDB().CancelAction(Link.id);
|
||||
return DoReturnA404();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ namespace OpenWifi {
|
||||
{"USERNAME", UInfo.email},
|
||||
{"ACTION_LINK",MicroService::instance().GetUIURI()}};
|
||||
Poco::File FormFile{Daemon()->AssetDir() + "/email_verification_success.html"};
|
||||
StorageService()->CompleteAction(Link.id);
|
||||
StorageService()->ActionLinksDB().CompleteAction(Link.id);
|
||||
SendHTMLFileBack(FormFile, FormVars);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace OpenWifi {
|
||||
NewLink.userId = UInfo1.Id;
|
||||
NewLink.created = std::time(nullptr);
|
||||
NewLink.expires = NewLink.created + (24*60*60);
|
||||
StorageService()->CreateAction(NewLink);
|
||||
StorageService()->ActionLinksDB().CreateAction(NewLink);
|
||||
|
||||
Poco::JSON::Object ReturnObj;
|
||||
SecurityObjects::UserInfoAndPolicy UInfo;
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace OpenWifi {
|
||||
NewLink.userId = UInfo1.Id;
|
||||
NewLink.created = std::time(nullptr);
|
||||
NewLink.expires = NewLink.created + (24*60*60);
|
||||
StorageService()->CreateAction(NewLink);
|
||||
StorageService()->ActionLinksDB().CreateAction(NewLink);
|
||||
|
||||
Poco::JSON::Object ReturnObj;
|
||||
SecurityObjects::UserInfoAndPolicy UInfo;
|
||||
|
||||
@@ -21,12 +21,14 @@ namespace OpenWifi {
|
||||
UserTokenDB_ = std::make_unique<OpenWifi::BaseTokenDB>("Tokens", "tok", dbType_,*Pool_, Logger());
|
||||
SubTokenDB_ = std::make_unique<OpenWifi::BaseTokenDB>("SubTokens", "stk", dbType_,*Pool_, Logger());
|
||||
PreferencesDB_ = std::make_unique<OpenWifi::PreferencesDB>("Preferences", "pre", dbType_,*Pool_, Logger());
|
||||
ActionLinksDB_ = std::make_unique<OpenWifi::ActionLinkDB>("Actions", "act", dbType_,*Pool_, Logger());
|
||||
|
||||
UserDB_->Create();
|
||||
SubDB_->Create();
|
||||
UserTokenDB_->Create();
|
||||
SubTokenDB_->Create();
|
||||
PreferencesDB_->Create();
|
||||
ActionLinksDB_->Create();
|
||||
|
||||
UserDB_->InitializeDefaultUser();
|
||||
|
||||
@@ -50,7 +52,7 @@ namespace OpenWifi {
|
||||
StorageService()->SubTokenDB().CleanExpiredTokens();
|
||||
StorageService()->UserTokenDB().CleanExpiredTokens();
|
||||
logger.information("Squiggy the DB: removing old actionLinks.");
|
||||
StorageService()->CleanOldActionLinks();
|
||||
StorageService()->ActionLinksDB().CleanOldActionLinks();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "storage/orm_users.h"
|
||||
#include "storage/orm_tokens.h"
|
||||
#include "storage/orm_preferences.h"
|
||||
#include "storage/orm_actionLinks.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
@@ -43,6 +44,7 @@ namespace OpenWifi {
|
||||
OpenWifi::BaseTokenDB & UserTokenDB() { return *UserTokenDB_; }
|
||||
OpenWifi::BaseTokenDB & SubTokenDB() { return *SubTokenDB_; }
|
||||
OpenWifi::PreferencesDB & PreferencesDB() { return *PreferencesDB_; }
|
||||
OpenWifi::ActionLinkDB & ActionLinksDB() { return *ActionLinksDB_; }
|
||||
|
||||
/*
|
||||
* All user management functions
|
||||
@@ -51,23 +53,11 @@ namespace OpenWifi {
|
||||
bool GetAvatar(const std::string & Admin, std::string &Id, Poco::TemporaryFile &FileName, std::string &Type, std::string & Name);
|
||||
bool DeleteAvatar(const std::string & Admin, std::string &Id);
|
||||
|
||||
/*
|
||||
* All ActionLinks functions
|
||||
*/
|
||||
bool CreateAction( SecurityObjects::ActionLink & A);
|
||||
bool DeleteAction(std::string &ActionId);
|
||||
bool CompleteAction(std::string &ActionId);
|
||||
bool CancelAction(std::string &ActionId);
|
||||
bool SentAction(std::string &ActionId);
|
||||
bool GetActionLink(std::string &ActionId, SecurityObjects::ActionLink &A);
|
||||
bool GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max=200);
|
||||
void CleanOldActionLinks();
|
||||
|
||||
private:
|
||||
int Create_Tables();
|
||||
int Create_AvatarTable();
|
||||
int Create_ActionLinkTable();
|
||||
|
||||
// int Create_ActionLinkTable();
|
||||
// int Create_Preferences();
|
||||
// int Create_UserTable();
|
||||
// int Create_TokensTable();
|
||||
@@ -79,6 +69,7 @@ namespace OpenWifi {
|
||||
std::unique_ptr<OpenWifi::BaseTokenDB> UserTokenDB_;
|
||||
std::unique_ptr<OpenWifi::BaseTokenDB> SubTokenDB_;
|
||||
std::unique_ptr<OpenWifi::PreferencesDB> PreferencesDB_;
|
||||
std::unique_ptr<OpenWifi::ActionLinkDB> ActionLinksDB_;
|
||||
|
||||
Poco::Timer Timer_;
|
||||
Archiver Archiver_;
|
||||
|
||||
124
src/storage/orm_actionLinks.cpp
Normal file
124
src/storage/orm_actionLinks.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-12-27.
|
||||
//
|
||||
|
||||
#include "orm_actionLinks.h"
|
||||
|
||||
/*
|
||||
"Id varchar(36),"
|
||||
"Action bigint,"
|
||||
"UserId text,"
|
||||
"template text,"
|
||||
"variables text,"
|
||||
"locale varchar,"
|
||||
"message text,"
|
||||
"sent bigint,"
|
||||
"created bigint,"
|
||||
"expires bigint,"
|
||||
"completed bigint,"
|
||||
"canceled bigint"
|
||||
*/
|
||||
|
||||
namespace OpenWifi {
|
||||
static ORM::FieldVec ActionLinksDB_Fields{
|
||||
ORM::Field{"id", 36, true},
|
||||
ORM::Field{"action", ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"userId", ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"actionTemplate", ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"variables", ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"locale", ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"message", ORM::FieldType::FT_TEXT},
|
||||
ORM::Field{"sent", ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"created", ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"expires", ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"completed", ORM::FieldType::FT_BIGINT},
|
||||
ORM::Field{"canceled", ORM::FieldType::FT_BIGINT}
|
||||
};
|
||||
|
||||
ActionLinkDB::ActionLinkDB(const std::string &Name, const std::string &ShortName, OpenWifi::DBType T,
|
||||
Poco::Data::SessionPool &P, Poco::Logger &L) :
|
||||
DB(T, Name.c_str(), ActionLinksDB_Fields,{}, P, L, ShortName.c_str()) {
|
||||
}
|
||||
|
||||
bool ActionLinkDB::CreateAction( SecurityObjects::ActionLink & A) {
|
||||
return CreateRecord(A);
|
||||
}
|
||||
|
||||
bool ActionLinkDB::GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max) {
|
||||
return GetRecords(0,Max,Links);
|
||||
}
|
||||
|
||||
bool ActionLinkDB::GetActionLink(std::string &ActionId, SecurityObjects::ActionLink &A) {
|
||||
return GetRecord("id",ActionId,A);
|
||||
}
|
||||
|
||||
bool ActionLinkDB::SentAction(std::string &ActionId) {
|
||||
SecurityObjects::ActionLink A;
|
||||
if(GetRecord("id",ActionId,A)) {
|
||||
A.sent = std::time(nullptr);
|
||||
return UpdateRecord("id",ActionId,A);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActionLinkDB::DeleteAction(std::string &ActionId) {
|
||||
return DeleteRecord("id",ActionId);
|
||||
}
|
||||
|
||||
bool ActionLinkDB::CompleteAction(std::string &ActionId) {
|
||||
SecurityObjects::ActionLink A;
|
||||
if(GetRecord("id",ActionId,A)) {
|
||||
A.completed = std::time(nullptr);
|
||||
return UpdateRecord("id",ActionId,A);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActionLinkDB::CancelAction(std::string &ActionId) {
|
||||
SecurityObjects::ActionLink A;
|
||||
if(GetRecord("id",ActionId,A)) {
|
||||
A.canceled = std::time(nullptr);
|
||||
return UpdateRecord("id",ActionId,A);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ActionLinkDB::CleanOldActionLinks() {
|
||||
uint64_t CutOff = std::time(nullptr) - (30 * 24 * 60 * 60);
|
||||
std::string WhereClause{" Created <= " + std::to_string(CutOff) + " "};
|
||||
DeleteRecords(WhereClause);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple,
|
||||
OpenWifi::SecurityObjects::ActionLink>::Convert(OpenWifi::ActionLinkRecordTuple &T, OpenWifi::SecurityObjects::ActionLink &U) {
|
||||
U.id = T.get<0>();
|
||||
U.action = T.get<1>();
|
||||
U.userId = T.get<2>();
|
||||
U.actionTemplate = T.get<3>();
|
||||
U.variables = OpenWifi::RESTAPI_utils::to_stringpair_array(T.get<4>());
|
||||
U.locale = T.get<5>();
|
||||
U.message = T.get<6>();
|
||||
U.sent = T.get<7>();
|
||||
U.created = T.get<8>();
|
||||
U.expires = T.get<9>();
|
||||
U.completed = T.get<10>();
|
||||
U.canceled = T.get<11>();
|
||||
}
|
||||
|
||||
template<> void ORM::DB<OpenWifi::ActionLinkRecordTuple,
|
||||
OpenWifi::SecurityObjects::ActionLink>::Convert(OpenWifi::SecurityObjects::ActionLink &U, OpenWifi::ActionLinkRecordTuple &T) {
|
||||
T.set<0>(U.id);
|
||||
T.set<1>(U.action);
|
||||
T.set<2>(U.userId);
|
||||
T.set<3>(U.actionTemplate);
|
||||
T.set<4>(OpenWifi::RESTAPI_utils::to_string(U.variables));
|
||||
T.set<5>(U.locale);
|
||||
T.set<6>(U.message);
|
||||
T.set<7>(U.sent);
|
||||
T.set<8>(U.created);
|
||||
T.set<9>(U.expires);
|
||||
T.set<10>(U.completed);
|
||||
T.set<11>(U.canceled);
|
||||
}
|
||||
45
src/storage/orm_actionLinks.h
Normal file
45
src/storage/orm_actionLinks.h
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-12-27.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "framework/orm.h"
|
||||
#include "RESTObjects/RESTAPI_SecurityObjects.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
typedef Poco::Tuple <
|
||||
std::string, // id
|
||||
uint64_t, // action
|
||||
std::string, // userId
|
||||
std::string, // actionTemplate
|
||||
std::string, // variables
|
||||
std::string, // locale
|
||||
std::string, // message
|
||||
uint64_t, // sent
|
||||
uint64_t, // created
|
||||
uint64_t, // expires
|
||||
uint64_t, // completed
|
||||
uint64_t // canceled
|
||||
> ActionLinkRecordTuple;
|
||||
typedef std::vector <ActionLinkRecordTuple> ActionLinkRecordTupleList;
|
||||
|
||||
class ActionLinkDB : public ORM::DB<ActionLinkRecordTuple, SecurityObjects::ActionLink> {
|
||||
public:
|
||||
ActionLinkDB( const std::string &name, const std::string &shortname, OpenWifi::DBType T, Poco::Data::SessionPool & P, Poco::Logger &L);
|
||||
|
||||
bool CreateAction( SecurityObjects::ActionLink & A);
|
||||
bool DeleteAction(std::string &ActionId);
|
||||
bool CompleteAction(std::string &ActionId);
|
||||
bool CancelAction(std::string &ActionId);
|
||||
bool SentAction(std::string &ActionId);
|
||||
bool GetActionLink(std::string &ActionId, SecurityObjects::ActionLink &A);
|
||||
bool GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max=200);
|
||||
void CleanOldActionLinks();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,201 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-11-08.
|
||||
//
|
||||
|
||||
#include "storage_actionLinks.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "StorageService.h"
|
||||
#include "RESTObjects/RESTAPI_SecurityObjects.h"
|
||||
#include "framework/MicroService.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
bool Convert(const ActionLinkRecord &T, SecurityObjects::ActionLink &U) {
|
||||
U.id = T.get<0>();
|
||||
U.action = T.get<1>();
|
||||
U.userId = T.get<2>();
|
||||
U.actionTemplate = T.get<3>();
|
||||
U.variables = RESTAPI_utils::to_stringpair_array(T.get<4>());
|
||||
U.locale = T.get<5>();
|
||||
U.message = T.get<6>();
|
||||
U.sent = T.get<7>();
|
||||
U.created = T.get<8>();
|
||||
U.expires = T.get<9>();
|
||||
U.completed = T.get<10>();
|
||||
U.canceled = T.get<11>();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Convert(const SecurityObjects::ActionLink &U, ActionLinkRecord &T) {
|
||||
T.set<0>(U.id);
|
||||
T.set<1>(U.action);
|
||||
T.set<2>(U.userId);
|
||||
T.set<3>(U.actionTemplate);
|
||||
T.set<4>(RESTAPI_utils::to_string(U.variables));
|
||||
T.set<5>(U.locale);
|
||||
T.set<6>(U.message);
|
||||
T.set<7>(U.sent);
|
||||
T.set<8>(U.created);
|
||||
T.set<9>(U.expires);
|
||||
T.set<10>(U.completed);
|
||||
T.set<11>(U.canceled);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StorageService::CreateAction( SecurityObjects::ActionLink & A) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Insert(Sess);
|
||||
std::string St2{
|
||||
"INSERT INTO ActionLinks (" + AllActionLinksFieldsForSelect + ") VALUES(" + AllActionLinksValuesForSelect + ")"};
|
||||
ActionLinkRecord AR;
|
||||
Convert(A, AR);
|
||||
Insert << ConvertParams(St2),
|
||||
Poco::Data::Keywords::use(AR);
|
||||
Insert.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::GetActions(std::vector<SecurityObjects::ActionLink> &Links, uint64_t Max) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
ActionLinkRecordList ARL;
|
||||
|
||||
std::string S{
|
||||
"SELECT " + AllActionLinksFieldsForSelect + " From ActionLinks where sent=0 and canceled=0 and completed=0"};
|
||||
Select << ConvertParams(S),
|
||||
Poco::Data::Keywords::into(ARL);
|
||||
Select.execute();
|
||||
|
||||
for(const auto &i:ARL) {
|
||||
SecurityObjects::ActionLink L;
|
||||
Convert(i,L);
|
||||
Links.emplace_back(L);
|
||||
}
|
||||
return true;
|
||||
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::GetActionLink(std::string &ActionId, SecurityObjects::ActionLink &A) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Select(Sess);
|
||||
|
||||
ActionLinkRecord AR;
|
||||
|
||||
std::string St2{
|
||||
"SELECT " + AllActionLinksFieldsForSelect + " From ActionLinks where id=?"};
|
||||
Select << ConvertParams(St2),
|
||||
Poco::Data::Keywords::into(AR),
|
||||
Poco::Data::Keywords::use(ActionId);
|
||||
Select.execute();
|
||||
|
||||
if(Select.rowsExtracted()==1) {
|
||||
Convert(AR, A);
|
||||
return true;
|
||||
}
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::SentAction(std::string &ActionId) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Update(Sess);
|
||||
|
||||
uint64_t Sent = std::time(nullptr);
|
||||
std::string St{"UPDATE ActionLinks set Sent=? where id=?"};
|
||||
Update << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(Sent),
|
||||
Poco::Data::Keywords::use(ActionId);
|
||||
Update.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::DeleteAction(std::string &ActionId) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
uint64_t Sent = std::time(nullptr);
|
||||
std::string St{"DELETE FROM ActionLinks where id=?"};
|
||||
Delete << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(ActionId);
|
||||
Delete.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::CompleteAction(std::string &ActionId) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Update(Sess);
|
||||
|
||||
uint64_t completed = std::time(nullptr);
|
||||
std::string St{"UPDATE ActionLinks set completed=? where id=?"};
|
||||
Update << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(completed),
|
||||
Poco::Data::Keywords::use(ActionId);
|
||||
Update.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool StorageService::CancelAction(std::string &ActionId) {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Update(Sess);
|
||||
|
||||
uint64_t canceled = std::time(nullptr);
|
||||
std::string St{"UPDATE ActionLinks set canceled=? where id=?"};
|
||||
Update << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(canceled),
|
||||
Poco::Data::Keywords::use(ActionId);
|
||||
Update.execute();
|
||||
return true;
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void StorageService::CleanOldActionLinks() {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
Poco::Data::Statement Delete(Sess);
|
||||
|
||||
uint64_t CutOff = std::time(nullptr) - (30 * 24 * 60 * 60);
|
||||
std::string St{"DELETE from ActionLinks where Created<=?"};
|
||||
Delete << ConvertParams(St),
|
||||
Poco::Data::Keywords::use(CutOff);
|
||||
Delete.execute();
|
||||
} catch (const Poco::Exception &E) {
|
||||
Logger().log(E);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
//
|
||||
// Created by stephane bourque on 2021-11-08.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Poco/Tuple.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
static const std::string AllActionLinksFieldsForCreation{
|
||||
"Id varchar(36),"
|
||||
"Action bigint,"
|
||||
"UserId text,"
|
||||
"template text,"
|
||||
"variables text,"
|
||||
"locale varchar,"
|
||||
"message text,"
|
||||
"sent bigint,"
|
||||
"created bigint,"
|
||||
"expires bigint,"
|
||||
"completed bigint,"
|
||||
"canceled bigint"
|
||||
};
|
||||
|
||||
static const std::string AllActionLinksFieldsForSelect {
|
||||
"Id, "
|
||||
"Action,"
|
||||
"UserId,"
|
||||
"template,"
|
||||
"variables,"
|
||||
"locale,"
|
||||
"message,"
|
||||
"sent,"
|
||||
"created,"
|
||||
"expires,"
|
||||
"completed,"
|
||||
"canceled"
|
||||
};
|
||||
|
||||
static const std::string AllActionLinksValuesForSelect{ "?,?,?,?,?,?,?,?,?,?,?,?" };
|
||||
|
||||
static const std::string AllActionLinksFieldsForUpdate {
|
||||
"Id=?, "
|
||||
"Action=?,"
|
||||
"UserId=?,"
|
||||
"template=?,"
|
||||
"variables=?,"
|
||||
"locale=?,"
|
||||
"message=?,"
|
||||
"sent=?,"
|
||||
"created=?,"
|
||||
"expires=?,"
|
||||
"completed=?,"
|
||||
"canceled=?"
|
||||
};
|
||||
|
||||
typedef Poco::Tuple <
|
||||
std::string, // id
|
||||
uint64_t, // action
|
||||
std::string, // userId
|
||||
std::string, // actionTemplate
|
||||
std::string, // variables
|
||||
std::string, // locale
|
||||
std::string, // message
|
||||
uint64_t, // sent
|
||||
uint64_t, // created
|
||||
uint64_t, // expires
|
||||
uint64_t, // completed
|
||||
uint64_t // canceled
|
||||
> ActionLinkRecord;
|
||||
typedef std::vector <ActionLinkRecord> ActionLinkRecordList;
|
||||
|
||||
}
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
#include "StorageService.h"
|
||||
#include "storage_avatar.h"
|
||||
#include "storage_actionLinks.h"
|
||||
|
||||
namespace OpenWifi {
|
||||
|
||||
int StorageService::Create_Tables() {
|
||||
Create_AvatarTable();
|
||||
Create_ActionLinkTable();
|
||||
// Create_ActionLinkTable();
|
||||
// Create_Preferences();
|
||||
// Create_UserTable();
|
||||
// Create_TokensTable();
|
||||
@@ -69,7 +68,7 @@ namespace OpenWifi {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
int StorageService::Create_ActionLinkTable() {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
@@ -83,7 +82,7 @@ namespace OpenWifi {
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
*/
|
||||
int StorageService::Create_AvatarTable() {
|
||||
try {
|
||||
Poco::Data::Session Sess = Pool_->get();
|
||||
|
||||
Reference in New Issue
Block a user