From 2e59a596c3b15f7d60d97c5b61839c4a1d6a3a76 Mon Sep 17 00:00:00 2001 From: Tina_Azure <-> Date: Fri, 12 May 2023 18:11:01 +0200 Subject: [PATCH] freelancer template management base (WIP) --- src/main.cpp | 53 ++++++++++++------- src/templateConstCollection.cpp | 8 +++ templates/freelancer_Template_Management.html | 18 +++---- ...lancer_Template_Management_Fulfilment.html | 37 +++++++++++++ 4 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 templates/freelancer_Template_Management_Fulfilment.html diff --git a/src/main.cpp b/src/main.cpp index 01fe180..83a49a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -645,12 +645,12 @@ int main(int argc, char *argv[]) { ([&, configuration](const crow::request& getRequest ) { auto& cookieCtx = app.get_context(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/").methods("POST"_method) - ([&, configuration](const crow::request& getRequest, string templateName ) { - auto& cookieCtx = app.get_context(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(postRequest); + string postRequestBody = postRequest.body; + Utilities::decodeString(postRequestBody); + vector splitRequest = Utilities::splitStringIntoVector(postRequestBody, '='); + vector 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); }); diff --git a/src/templateConstCollection.cpp b/src/templateConstCollection.cpp index 8b61e54..a456c99 100644 --- a/src/templateConstCollection.cpp +++ b/src/templateConstCollection.cpp @@ -25,6 +25,7 @@ namespace TemplateConstCollection { const static std::string TEMPLATE_FREELANCER_REDIRECT_PROFILE = "freelancer_Redirect_Profile.html"; const static std::string TEMPLATE_FREELANCER_PROFILE = "freelancer_Profile.html"; const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT = "freelancer_Template_Management.html"; + const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT = "freelancer_Template_Management_Fulfilment.html"; //Mustache Error/Success variable names const static std::string MUSTACHE_ERROR_COMMISSIONS_CLOSED = "ERROR_COMMISSIONS_CLOSED"; @@ -52,6 +53,7 @@ namespace TemplateConstCollection { const static std::string MUSTACHE_REGISTRATION_SUCCESS = "REGISTRATION_SUCCESS"; const static std::string MUSTACHE_RESET_SUCCESS = "RESET_SUCCESS"; const static std::string MUSTACHE_LOGIN_SUCCESS = "LOGIN_SUCCESS"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_ERROR_NO_TEMPLATE = "TEMPLATE_OPERATION_ERROR_NO_TEMPLATE"; //Mustache Cookie variable names const static std::string MUSTACHE_COOKIE_LOGGED_IN = "COOKIE_LOGGED_IN"; @@ -61,6 +63,12 @@ namespace TemplateConstCollection { const static std::string MUSTACHE_PAGINATION_NUMBERS = "PAGINATION_NUMBERS"; const static std::string MUSTACHE_PAGINATION_PREVIOUS = "PAGINATION_PREVIOUS"; const static std::string MUSTACHE_PAGINATION_NEXT = "PAGINATION_NEXT"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_VIEW = "view"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_EDIT = "edit"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_DELETE = "delete"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_VIEW = "OPERATION_VIEW"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_EDIT = "OPERATION_EDIT"; + const static std::string MUSTACHE_FREELANCER_TEMPLATE_OPERATION_FULFILMENT_DELETE = "OPERATION_DELETE"; //Cookie names const static std::string COOKIE_LOGIN_KEY = "loginKey"; diff --git a/templates/freelancer_Template_Management.html b/templates/freelancer_Template_Management.html index 2a1b509..9072398 100644 --- a/templates/freelancer_Template_Management.html +++ b/templates/freelancer_Template_Management.html @@ -8,24 +8,18 @@ Please Log in. {{/COOKIE_LOGGED_IN}} {{#COOKIE_LOGGED_IN}} -

Freelancer: {{freelancername}}

-
Basic Profile:
-
{{freelancerbasicinformation}}
+

Freelancer: {{freelanceremail}}


-
Detailed Profile:
-
{{freelancergeneralinformation}}
-
- {{> templateIncludes/returnToIndexButton.html.html}}
{{#templates}} @@ -33,6 +27,8 @@
{{name}} -
- - - + + + +
{{/COOKIE_LOGGED_IN}} {{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}} +
+ {{> templateIncludes/returnToIndexButton.html.html}} diff --git a/templates/freelancer_Template_Management_Fulfilment.html b/templates/freelancer_Template_Management_Fulfilment.html new file mode 100644 index 0000000..cb1716c --- /dev/null +++ b/templates/freelancer_Template_Management_Fulfilment.html @@ -0,0 +1,37 @@ + + + + {{> templateIncludes/style.css.html}} + + +

Freelancer: {{freelancername}}

+

Template: {{templatename}}

+
Contact Information:
+
+ {{contactdata}}
+ {{contactinformation}} +
+
+
Payment Information:
+
+ Prefered Currency: {{currencypreference}}
+ Price: {{pricetotal}} - Upfront: {{priceupfront}} - On Delivery: {{priceondeliver}}
+
+
+
Description:
+
{{content}}
+
+
+ +
+
+ +
+
+ {{> templateIncludes/returnToIndexButton.html.html}} + + + + + + \ No newline at end of file