create new submission alias
This commit is contained in:
@@ -490,7 +490,7 @@ namespace Database {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* //todo:implement
|
/*
|
||||||
* Executes the prepared statement INSERT_FREELANCER_FILE_SUBMISSION_ALIAS
|
* Executes the prepared statement INSERT_FREELANCER_FILE_SUBMISSION_ALIAS
|
||||||
* Takes an open pqxx::connection and aliasname as {ID}/{Alias}, freelancerid, filename
|
* Takes an open pqxx::connection and aliasname as {ID}/{Alias}, freelancerid, filename
|
||||||
* returns errorLevel
|
* returns errorLevel
|
||||||
@@ -498,10 +498,10 @@ namespace Database {
|
|||||||
* 1 = query error
|
* 1 = query error
|
||||||
* 2 = critical error
|
* 2 = critical error
|
||||||
*/
|
*/
|
||||||
int executePreparedStatement_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS(pqxx::connection &connection, const int freelancerID, const std::string& fileName, const std::string& aliasname) {
|
int executePreparedStatement_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS(pqxx::connection &connection, const int freelancerID, const std::string& fileName, const std::string& aliasName) {
|
||||||
try {
|
try {
|
||||||
pqxx::work work(connection);
|
pqxx::work work(connection);
|
||||||
work.exec_prepared(PREPARED_STATEMENT_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS, freelancerID, fileName, aliasname);
|
work.exec_prepared(PREPARED_STATEMENT_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS, freelancerID, fileName, aliasName);
|
||||||
work.commit();
|
work.commit();
|
||||||
}
|
}
|
||||||
catch (pqxx::sql_error const &e) {
|
catch (pqxx::sql_error const &e) {
|
||||||
|
77
src/main.cpp
77
src/main.cpp
@@ -1212,19 +1212,90 @@ int main(int argc, char *argv[]) {
|
|||||||
/*
|
/*
|
||||||
* Page for freelancer to generate link to a particular submission
|
* Page for freelancer to generate link to a particular submission
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/freelancer/submissionManagement/view/generateLink")
|
CROW_ROUTE(app, "/freelancer/submissionManagement/view/generateLink").methods(crow::HTTPMethod::POST)
|
||||||
([&, configuration](const crow::request& getRequest) {
|
([&, configuration](const crow::request& postRequest) {
|
||||||
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
|
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
|
||||||
crow::mustache::context ctx;
|
crow::mustache::context ctx;
|
||||||
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
||||||
|
string postRequestBody = postRequest.body;
|
||||||
|
Utilities::decodeString(postRequestBody);
|
||||||
|
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
||||||
|
string fileName;
|
||||||
|
for (const string& item : splitPostRequestBody) {
|
||||||
|
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||||
|
if (splitItem.at(0) == "filename")
|
||||||
|
fileName = splitItem.at(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!fileName.empty()) {
|
||||||
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
|
Database::prepareStatements(databaseConnection, {
|
||||||
|
ID_SELECT_FREELANCER_ID
|
||||||
|
});
|
||||||
|
|
||||||
|
string freelancerID;
|
||||||
|
pqxx::result freelancerIDResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
||||||
|
freelancerID = freelancerIDResult.at(0).at(0).c_str();
|
||||||
|
|
||||||
|
ctx["filename"] = fileName;
|
||||||
|
ctx["domain"] = configuration.domain + "/commissionSubmission";
|
||||||
|
ctx["freelancerid"] = freelancerID;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx[MUSTACHE_POST_ERROR] = true;
|
||||||
|
ctx[MUSTACHE_REQUEST_NOT_FILLED] = true;
|
||||||
|
}
|
||||||
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
||||||
}
|
}
|
||||||
auto page = crow::mustache::load(TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK);
|
auto page = crow::mustache::load(TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK);
|
||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Page for freelancer to generate link to a particular submission todo:look into inability to display " " and link to "#"
|
||||||
|
*/
|
||||||
|
CROW_ROUTE(app, "/freelancer/submissionManagement/view/generateLink/fulfilment/<string>").methods(crow::HTTPMethod::POST)
|
||||||
|
([&, configuration](const crow::request& postRequest, const string& fileName) {
|
||||||
|
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
|
||||||
|
crow::mustache::context ctx;
|
||||||
|
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
|
||||||
|
string postRequestBody = postRequest.body;
|
||||||
|
Utilities::decodeString(postRequestBody);
|
||||||
|
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
|
||||||
|
string alias;
|
||||||
|
for (const string& item : splitPostRequestBody) {
|
||||||
|
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
|
||||||
|
if (splitItem.at(0) == "alias")
|
||||||
|
alias = splitItem.at(1);
|
||||||
|
}
|
||||||
|
if (!alias.empty() && !fileName.empty()) {
|
||||||
|
cout << "filename: " << fileName << endl;
|
||||||
|
cout << "alias: " << alias << endl;
|
||||||
|
pqxx::connection databaseConnection(configuration.databaseConnectionString);
|
||||||
|
Database::prepareStatements(databaseConnection, {
|
||||||
|
ID_SELECT_FREELANCER_ID,
|
||||||
|
ID_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS
|
||||||
|
});
|
||||||
|
|
||||||
|
pqxx::result freelancerIDResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL));
|
||||||
|
string freelancerID = freelancerIDResult.at(0).at(0).c_str();
|
||||||
|
string aliasName = freelancerID;
|
||||||
|
aliasName.append("/");
|
||||||
|
aliasName.append(alias);
|
||||||
|
ctx["submissionLink"] = configuration.domain + "/commissionSubmission/" + aliasName;
|
||||||
|
if(Database::executePreparedStatement_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS(databaseConnection, stoi(freelancerID), fileName, aliasName) > 0)
|
||||||
|
ctx[MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR_INVALID] = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx[MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR] = true;
|
||||||
|
ctx[MUSTACHE_REQUEST_NOT_FILLED] = true;
|
||||||
|
}
|
||||||
|
ctx[MUSTACHE_COOKIE_LOGGED_IN] = true;
|
||||||
|
}
|
||||||
|
auto page = crow::mustache::load(TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK_FULFILMENT);
|
||||||
|
return page.render(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -37,6 +37,7 @@ namespace TemplateConstCollection {
|
|||||||
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_ADD = "freelancer_Submission_Management_Add.html";
|
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_ADD = "freelancer_Submission_Management_Add.html";
|
||||||
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW = "freelancer_Submission_Management_View.html";
|
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW = "freelancer_Submission_Management_View.html";
|
||||||
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK = "freelancer_Submission_Management_View_Generate_link.html";
|
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK = "freelancer_Submission_Management_View_Generate_link.html";
|
||||||
|
const static std::string TEMPLATE_FREELANCER_SUBMISSION_MANAGEMENT_VIEW_GENERATE_LINK_FULFILMENT = "freelancer_Submission_Management_View_Generate_link_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";
|
||||||
@@ -71,6 +72,9 @@ namespace TemplateConstCollection {
|
|||||||
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR = "ALIAS_CREATION_ERROR";
|
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR = "ALIAS_CREATION_ERROR";
|
||||||
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR_DUPLICATE = "ALIAS_CREATION_ERROR_DUPLICATE";
|
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR_DUPLICATE = "ALIAS_CREATION_ERROR_DUPLICATE";
|
||||||
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR_UNNAMED = "ALIAS_CREATION_ERROR_UNNAMED";
|
const static std::string MUSTACHE_FREELANCER_ALIAS_CREATION_ERROR_UNNAMED = "ALIAS_CREATION_ERROR_UNNAMED";
|
||||||
|
const static std::string MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR = "SUBMISSION_ALIAS_ERROR";
|
||||||
|
const static std::string MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR_INVALID = "SUBMISSION_ALIAS_ERROR_INVALID";
|
||||||
|
const static std::string MUSTACHE_POST_ERROR = "POST_ERROR";
|
||||||
|
|
||||||
//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";
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
{{> templateIncludes/style.css.html}}
|
{{> templateIncludes/style.css.html}}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<h2>Submission Management</h2>
|
||||||
{{^COOKIE_LOGGED_IN}}
|
{{^COOKIE_LOGGED_IN}}
|
||||||
Please Log in.
|
Please Log in.
|
||||||
{{/COOKIE_LOGGED_IN}}
|
{{/COOKIE_LOGGED_IN}}
|
||||||
@@ -28,6 +29,11 @@
|
|||||||
<button type="submit" name="filename" value="{{filename}}" class="button">Delete</button>
|
<button type="submit" name="filename" value="{{filename}}" class="button">Delete</button>
|
||||||
</form>
|
</form>
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
<form action="/freelancer/submissionManagement/view/viewLink" method="post">
|
||||||
|
<button type="submit" name="filename" value="{{filename}}" class="button">View Links</button>
|
||||||
|
</form>
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
<form action="/freelancer/submissionManagement/view/generateLink" method="post">
|
<form action="/freelancer/submissionManagement/view/generateLink" method="post">
|
||||||
<button type="submit" name="filename" value="{{filename}}" class="button">Generate Link</button>
|
<button type="submit" name="filename" value="{{filename}}" class="button">Generate Link</button>
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{{> templateIncludes/style.css.html}}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h2>Submission Management: New Link for {{filename}}</h2>
|
||||||
|
{{^COOKIE_LOGGED_IN}}
|
||||||
|
Please Log in.
|
||||||
|
{{/COOKIE_LOGGED_IN}}
|
||||||
|
{{#COOKIE_LOGGED_IN}}
|
||||||
|
{{^POST_ERROR}}
|
||||||
|
<form action="/freelancer/submissionManagement/view/generateLink/fulfilment/{{filename}}" method="post">
|
||||||
|
<p>Link Preview: {{domain}}/{{freelancerid}}/</label><input type="text" id="alias" name="alias" value=""><br>
|
||||||
|
<button type="submit" class="button">Create Link</button>
|
||||||
|
</form>
|
||||||
|
{{/POST_ERROR}}
|
||||||
|
{{#POST_ERROR}}
|
||||||
|
{{#REQUEST_NOT_FILLED}}
|
||||||
|
<p>Error: Invalid Request</p>
|
||||||
|
{{/REQUEST_NOT_FILLED}}
|
||||||
|
{{/POST_ERROR}}
|
||||||
|
{{/COOKIE_LOGGED_IN}}
|
||||||
|
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
||||||
|
<br>
|
||||||
|
{{> templateIncludes/returnToIndexButton.html.html}}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@@ -0,0 +1,32 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
{{> templateIncludes/style.css.html}}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{{^COOKIE_LOGGED_IN}}
|
||||||
|
Please Log in.
|
||||||
|
{{/COOKIE_LOGGED_IN}}
|
||||||
|
{{#COOKIE_LOGGED_IN}}
|
||||||
|
{{^SUBMISSION_ALIAS_ERROR}}
|
||||||
|
<div>
|
||||||
|
Link successfully created: <a href="https://{{submissionLink}}">{{submissionLink}}</a>
|
||||||
|
</div>
|
||||||
|
{{/SUBMISSION_ALIAS_ERROR}}
|
||||||
|
{{#SUBMISSION_ALIAS_ERROR}}
|
||||||
|
{{#SUBMISSION_ALIAS_ERROR_INVALID}}
|
||||||
|
<div>
|
||||||
|
Alias is invalid/already in use
|
||||||
|
</div>
|
||||||
|
{{/SUBMISSION_ALIAS_ERROR_INVALID}}
|
||||||
|
{{#REQUEST_NOT_FILLED}}
|
||||||
|
<div>
|
||||||
|
Request is invalid
|
||||||
|
</div>
|
||||||
|
{{/REQUEST_NOT_FILLED}}
|
||||||
|
{{/SUBMISSION_ALIAS_ERROR}}
|
||||||
|
{{/COOKIE_LOGGED_IN}}
|
||||||
|
|
||||||
|
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in New Issue
Block a user