From ed370e79799d87848dc2cfa297018ff782533d72 Mon Sep 17 00:00:00 2001 From: Tina_Azure <-> Date: Fri, 12 May 2023 00:03:25 +0200 Subject: [PATCH] Freelancer Template base Managment page --- src/main.cpp | 42 ++++++++++++++++++- src/templateConstCollection.cpp | 1 + src/utilities.cpp | 18 ++++++++ templates/freelancer_Profile.html | 24 +++++++---- templates/freelancer_Template_Management.html | 41 ++++++++++++++++++ 5 files changed, 116 insertions(+), 10 deletions(-) create mode 100644 templates/freelancer_Template_Management.html diff --git a/src/main.cpp b/src/main.cpp index a46c486..01fe180 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -625,7 +625,7 @@ int main(int argc, char *argv[]) { }); /* - * Page for freelancer to sign up + * Freelancer Profile page */ CROW_ROUTE(app, "/freelancer/profile") ([&, configuration](const crow::request& getRequest ) { @@ -638,6 +638,46 @@ int main(int argc, char *argv[]) { return page.render(ctx); }); + /* + * Page for freelancer to create/delete/edit Templates + */ + CROW_ROUTE(app, "/freelancer/templateManagement") + ([&, 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[MUSTACHE_COOKIE_LOGGED_IN] = true; + } + auto page = crow::mustache::load(templateHTML); + return page.render(ctx); + }); + + /* + * 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)) + ctx[MUSTACHE_COOKIE_LOGGED_IN] = true; + + + + + + + + + + + auto page = crow::mustache::load(templateHTML); + return page.render(ctx); + }); + diff --git a/src/templateConstCollection.cpp b/src/templateConstCollection.cpp index 9ea0d8c..8b61e54 100644 --- a/src/templateConstCollection.cpp +++ b/src/templateConstCollection.cpp @@ -24,6 +24,7 @@ namespace TemplateConstCollection { const static std::string TEMPLATE_PASSWORD_RESET_FULFILMENT = "passwordReset_Fulfilment.html"; 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"; //Mustache Error/Success variable names const static std::string MUSTACHE_ERROR_COMMISSIONS_CLOSED = "ERROR_COMMISSIONS_CLOSED"; diff --git a/src/utilities.cpp b/src/utilities.cpp index 3c13e54..14d39ac 100644 --- a/src/utilities.cpp +++ b/src/utilities.cpp @@ -504,5 +504,23 @@ namespace Utilities { Database::executePreparedStatement_UPDATE_EXPIRATION_LOGIN_LOCK_OUT(connection, emailAddress, configuration.bruteForceMitigationLockSeconds); } } + + crow::json::wvalue getFreelancerTemplates(const Utilities::config& configuration, const std::string& emailAddress) { + crow::json::wvalue resultJsonFreelancerTemplate; + + pqxx::connection databaseConnection(configuration.databaseConnectionString); + Database::prepareStatements(databaseConnection, { + ID_SELECT_FREELANCER_ID, + ID_SELECT_FREELANCER_TEMPLATES + }); + pqxx::result idResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, emailAddress); + if (!idResult.empty()) + { + int freelancerID = std::stoi(idResult.at(0).at(0).c_str()); + pqxx::result resultFreelancerTemplates = Database::executePreparedStatement_SELECT_FREELANCER_TEMPLATES(databaseConnection, freelancerID); + resultJsonFreelancerTemplate = Database::convertResultToJSON(resultFreelancerTemplates, "templates"); + } + return resultJsonFreelancerTemplate; + } } #endif \ No newline at end of file diff --git a/templates/freelancer_Profile.html b/templates/freelancer_Profile.html index 0ec0c30..63a6943 100644 --- a/templates/freelancer_Profile.html +++ b/templates/freelancer_Profile.html @@ -9,15 +9,21 @@ Please Log in. {{/COOKIE_LOGGED_IN}} {{#COOKIE_LOGGED_IN}} -
-
- -
-
- -
-
-
+
+
+ +
+
+ +
+
+
+
+
+ +
+
+
diff --git a/templates/freelancer_Template_Management.html b/templates/freelancer_Template_Management.html new file mode 100644 index 0000000..2a1b509 --- /dev/null +++ b/templates/freelancer_Template_Management.html @@ -0,0 +1,41 @@ + + + + {{> templateIncludes/style.css.html}} + + + {{^COOKIE_LOGGED_IN}} + Please Log in. + {{/COOKIE_LOGGED_IN}} + {{#COOKIE_LOGGED_IN}} +

Freelancer: {{freelancername}}

+
Basic Profile:
+
{{freelancerbasicinformation}}
+
+
Detailed Profile:
+
{{freelancergeneralinformation}}
+
+ {{> templateIncludes/returnToIndexButton.html.html}} +
+ + {{#templates}} + + + + + {{/templates}} +
{{name}} + + + + + +
+ {{/COOKIE_LOGGED_IN}} + {{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}} + + + + + + \ No newline at end of file