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);
});

View File

@ -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";

View File

@ -8,24 +8,18 @@
Please Log in.
{{/COOKIE_LOGGED_IN}}
{{#COOKIE_LOGGED_IN}}
<h2>Freelancer: {{freelancername}}</h2>
<div>Basic Profile:</div>
<div>{{freelancerbasicinformation}}</div>
<h2>Freelancer: {{freelanceremail}}</h2>
<br>
<div>Detailed Profile:</div>
<div>{{freelancergeneralinformation}}</div>
<br>
{{> templateIncludes/returnToIndexButton.html.html}}
<br>
<table>
{{#templates}}
<tr>
<th>{{name}}</th>
<th>
<form action="/freelancer/templateManagement/template/{{name}}" name="templateid" value="{{id}}" method="post">
<button type="submit" name="templateaction" value="{{view}}" class="button">View</button>
<button type="submit" name="templateaction" value="{{edit}}" class="button">Edit</button>
<button type="submit" name="templateaction" value="{{delete}}" class="button">Delete</button>
<form action="/freelancer/templateManagement/template/{{name}}" method="post">
<button type="submit" name="templateaction" value="view|{{id}}" class="button">View</button>
<button type="submit" name="templateaction" value="edit|{{id}}" class="button">Edit</button>
<button type="submit" name="templateaction" value="delete|{{id}}" class="button">Delete</button>
</form>
</th>
</tr>
@ -33,6 +27,8 @@
</table>
{{/COOKIE_LOGGED_IN}}
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
<br>
{{> templateIncludes/returnToIndexButton.html.html}}
</body>
</html>

View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html>
<head>
{{> templateIncludes/style.css.html}}
</head>
<body>
<h2>Freelancer: {{freelancername}}</h2>
<h3>Template: {{templatename}}</h3>
<div>Contact Information:</div>
<div>
{{contactdata}}<br>
{{contactinformation}}
</div>
<br>
<div>Payment Information:</div>
<div>
Prefered Currency: {{currencypreference}}<br>
Price: {{pricetotal}} - Upfront: {{priceupfront}} - On Delivery: {{priceondeliver}}<br>
</div>
<br>
<div>Description:</div>
<div>{{content}}</div>
<br>
<form action="/freelancer/profile" method="get">
<button type="submit" class="button">Return to profile</button>
</form>
<form action="/freelancer/templateManagement" method="get">
<button type="submit" class="button">Return to Template Management</button>
</form>
<br>
{{> templateIncludes/returnToIndexButton.html.html}}
</body>
</html>