freelancer template management base (WIP)
This commit is contained in:
53
src/main.cpp
53
src/main.cpp
@ -645,12 +645,12 @@ int main(int argc, char *argv[]) {
|
|||||||
([&, configuration](const crow::request& getRequest ) {
|
([&, configuration](const crow::request& getRequest ) {
|
||||||
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
||||||
crow::mustache::context ctx;
|
crow::mustache::context ctx;
|
||||||
string templateHTML = TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT;
|
|
||||||
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
||||||
ctx = Utilities::getFreelancerTemplates(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
ctx = Utilities::getFreelancerTemplates(configuration, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
||||||
|
ctx["freelanceremail"] = cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL);
|
||||||
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
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);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -658,23 +658,40 @@ int main(int argc, char *argv[]) {
|
|||||||
* Page for freelancer to create/delete/edit Templates
|
* Page for freelancer to create/delete/edit Templates
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/freelancer/templateManagement/template/<string>").methods("POST"_method)
|
CROW_ROUTE(app, "/freelancer/templateManagement/template/<string>").methods("POST"_method)
|
||||||
([&, configuration](const crow::request& getRequest, string templateName ) {
|
([&, configuration](const crow::request& postRequest, string templateName ) {
|
||||||
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
|
||||||
crow::mustache::context ctx;
|
string postRequestBody = postRequest.body;
|
||||||
string templateHTML = TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT;
|
Utilities::decodeString(postRequestBody);
|
||||||
if (Utilities::checkCookieLoginState(configuration, cookieCtx))
|
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;
|
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
||||||
|
}
|
||||||
|
auto page = crow::mustache::load(TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
auto page = crow::mustache::load(templateHTML);
|
|
||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace TemplateConstCollection {
|
|||||||
const static std::string TEMPLATE_FREELANCER_REDIRECT_PROFILE = "freelancer_Redirect_Profile.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_PROFILE = "freelancer_Profile.html";
|
||||||
const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT = "freelancer_Template_Management.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
|
//Mustache Error/Success variable names
|
||||||
const static std::string MUSTACHE_ERROR_COMMISSIONS_CLOSED = "ERROR_COMMISSIONS_CLOSED";
|
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_REGISTRATION_SUCCESS = "REGISTRATION_SUCCESS";
|
||||||
const static std::string MUSTACHE_RESET_SUCCESS = "RESET_SUCCESS";
|
const static std::string MUSTACHE_RESET_SUCCESS = "RESET_SUCCESS";
|
||||||
const static std::string MUSTACHE_LOGIN_SUCCESS = "LOGIN_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
|
//Mustache Cookie variable names
|
||||||
const static std::string MUSTACHE_COOKIE_LOGGED_IN = "COOKIE_LOGGED_IN";
|
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_NUMBERS = "PAGINATION_NUMBERS";
|
||||||
const static std::string MUSTACHE_PAGINATION_PREVIOUS = "PAGINATION_PREVIOUS";
|
const static std::string MUSTACHE_PAGINATION_PREVIOUS = "PAGINATION_PREVIOUS";
|
||||||
const static std::string MUSTACHE_PAGINATION_NEXT = "PAGINATION_NEXT";
|
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
|
//Cookie names
|
||||||
const static std::string COOKIE_LOGIN_KEY = "loginKey";
|
const static std::string COOKIE_LOGIN_KEY = "loginKey";
|
||||||
|
@ -8,24 +8,18 @@
|
|||||||
Please Log in.
|
Please Log in.
|
||||||
{{/COOKIE_LOGGED_IN}}
|
{{/COOKIE_LOGGED_IN}}
|
||||||
{{#COOKIE_LOGGED_IN}}
|
{{#COOKIE_LOGGED_IN}}
|
||||||
<h2>Freelancer: {{freelancername}}</h2>
|
<h2>Freelancer: {{freelanceremail}}</h2>
|
||||||
<div>Basic Profile:</div>
|
|
||||||
<div>{{freelancerbasicinformation}}</div>
|
|
||||||
<br>
|
<br>
|
||||||
<div>Detailed Profile:</div>
|
|
||||||
<div>{{freelancergeneralinformation}}</div>
|
|
||||||
<br>
|
|
||||||
{{> templateIncludes/returnToIndexButton.html.html}}
|
|
||||||
<br>
|
<br>
|
||||||
<table>
|
<table>
|
||||||
{{#templates}}
|
{{#templates}}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{name}}</th>
|
<th>{{name}}</th>
|
||||||
<th>
|
<th>
|
||||||
<form action="/freelancer/templateManagement/template/{{name}}" name="templateid" value="{{id}}" method="post">
|
<form action="/freelancer/templateManagement/template/{{name}}" method="post">
|
||||||
<button type="submit" name="templateaction" value="{{view}}" class="button">View</button>
|
<button type="submit" name="templateaction" value="view|{{id}}" class="button">View</button>
|
||||||
<button type="submit" name="templateaction" value="{{edit}}" class="button">Edit</button>
|
<button type="submit" name="templateaction" value="edit|{{id}}" class="button">Edit</button>
|
||||||
<button type="submit" name="templateaction" value="{{delete}}" class="button">Delete</button>
|
<button type="submit" name="templateaction" value="delete|{{id}}" class="button">Delete</button>
|
||||||
</form>
|
</form>
|
||||||
</th>
|
</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -33,6 +27,8 @@
|
|||||||
</table>
|
</table>
|
||||||
{{/COOKIE_LOGGED_IN}}
|
{{/COOKIE_LOGGED_IN}}
|
||||||
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
||||||
|
<br>
|
||||||
|
{{> templateIncludes/returnToIndexButton.html.html}}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
37
templates/freelancer_Template_Management_Fulfilment.html
Normal file
37
templates/freelancer_Template_Management_Fulfilment.html
Normal 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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user