freelancer template management base (WIP)

This commit is contained in:
Tina_Azure
2023-05-12 18:11:01 +02:00
parent ed370e7979
commit 2e59a596c3
4 changed files with 87 additions and 29 deletions

View File

@ -645,12 +645,12 @@ int main(int argc, char *argv[]) {
([&, configuration](const crow::request& getRequest ) {
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
crow::mustache::context ctx;
string templateHTML = TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT;
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx = Utilities::getFreelancerTemplates(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
ctx["freelanceremail"] = cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL);
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
}
auto page = crow::mustache::load(templateHTML);
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT);
return page.render(ctx);
});
@ -658,23 +658,40 @@ int main(int argc, char *argv[]) {
* Page for freelancer to create/delete/edit Templates
*/
CROW_ROUTE(app, "/freelancer/templateManagement/template/<string>").methods("POST"_method)
([&, configuration](const crow::request& getRequest, string templateName ) {
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
crow::mustache::context ctx;
string templateHTML = TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT;
if (Utilities::checkCookieLoginState(configuration, cookieCtx))
([&, configuration](const crow::request& postRequest, string templateName ) {
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
string postRequestBody = postRequest.body;
Utilities::decodeString(postRequestBody);
vector<string> splitRequest = Utilities::splitStringIntoVector(postRequestBody, '=');
vector<string> splitValues = Utilities::splitStringIntoVector(splitRequest.at(1), '|');
bool cookieLoginStateValid = Utilities::checkCookieLoginState(configuration, cookieCtx);
pqxx::connection databaseConnection(configuration.databaseConnectionString);
crow::json::wvalue resultJsonTemplate;
/*
* only selects a template if the login state is valid, it is possible to get the template of another user loaded since they are by design public
* but that should be a non issue since any operation that changes data will be performed with explicit ownership validation
*/
if (cookieLoginStateValid) {
Database::prepareStatement(databaseConnection, ID_SELECT_TEMPLATE);
pqxx::result resultTemplate = Database::executePreparedStatement_SELECT_TEMPLATE(databaseConnection, stoi(splitValues.at(1)));
resultJsonTemplate = Database::convertResultRowToJSON(resultTemplate);
}
crow::mustache::context ctx(resultJsonTemplate);
if (cookieLoginStateValid) {
string templateOperation = splitValues.at(0);
if (templateOperation == MUSTACHE_FREELANCER_TEMPLATE_OPERATION_VIEW) {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_VIEW] = true;
} else if (templateOperation == MUSTACHE_FREELANCER_TEMPLATE_OPERATION_EDIT) {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT] = true;
} else if (templateOperation == MUSTACHE_FREELANCER_TEMPLATE_OPERATION_DELETE) {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE] = true;
} else {
ctx[MUSTACHE_FREELANCER_TEMPLATE_OPERATION_ERROR_NO_TEMPLATE] = true;
}
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
auto page = crow::mustache::load(templateHTML);
}
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT);
return page.render(ctx);
});