diff --git a/src/main.cpp b/src/main.cpp index 43e88ef..d9cedd8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1142,7 +1142,10 @@ int main(int argc, char *argv[]) { pqxx::connection databaseConnection(configuration.databaseConnectionString); Database::prepareStatement(databaseConnection, ID_SELECT_FREELANCER_FILE_SUBMISSION_PATH); - pqxx::result submissionFilePathResult = Database::executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_PATH(databaseConnection, fileName, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL)); + string decodedFileName = fileName; + Utilities::decodeString(decodedFileName); + + pqxx::result submissionFilePathResult = Database::executePreparedStatement_SELECT_FREELANCER_FILE_SUBMISSION_PATH(databaseConnection, decodedFileName, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL)); if (submissionFilePathResult.empty()) return crow::response(404, "File does not exist."); @@ -1240,7 +1243,7 @@ int main(int argc, char *argv[]) { }); /* - * Page for freelancer to delete existing Link to a submission todo:implement proper encoding decoding to avoid routing errors # causes routing to cut off + * Page for freelancer to delete existing Link to a submission */ CROW_ROUTE(app, "/freelancer/submissionManagement/view/viewLink////delete").methods(crow::HTTPMethod::GET) ([&, configuration](const crow::request& getRequest, const int freelancerID, const string& aliasName, const string& fileName) { @@ -1286,6 +1289,16 @@ int main(int argc, char *argv[]) { pqxx::result freelancerIDResult = Database::executePreparedStatement_SELECT_FREELANCER_ID(databaseConnection, cookieCtx.get_cookie(COOKIE_FREELANCER_EMAIL)); freelancerID = freelancerIDResult.at(0).at(0).c_str(); + string allowedFiletypes, forbiddenChars; + for (const string &character: configuration.submissionBlacklistedCharacters) { + if (!forbiddenChars.empty()) { + forbiddenChars.append(","); + } + forbiddenChars.append(character); + string encodedChar = character; + Utilities::encodeString(encodedChar); + } + ctx[MUSTACHE_FREELANCER_FORBIDDEN_FILE_CHARACTER_LIST_COMMA_SEPARATED] = forbiddenChars; ctx["filename"] = fileName; ctx["domain"] = configuration.domain + "/commissionSubmission"; ctx["freelancerid"] = freelancerID; @@ -1301,7 +1314,7 @@ int main(int argc, char *argv[]) { }); /* - * Page for freelancer to generate link to a particular submission todo:look into inability to display " " and link to "#" + * Page for freelancer to generate link to a particular submission */ CROW_ROUTE(app, "/freelancer/submissionManagement/view/generateLink/fulfilment/").methods(crow::HTTPMethod::POST) ([&, configuration](const crow::request& postRequest, const string& fileName) { @@ -1317,9 +1330,21 @@ int main(int argc, char *argv[]) { if (splitItem.at(0) == "alias") alias = splitItem.at(1); } - if (!alias.empty() && !fileName.empty()) { - cout << "filename: " << fileName << endl; - cout << "alias: " << alias << endl; + + bool aliasInvalid = false; + if (alias.empty()) + aliasInvalid = true; + else { + for (const string& blacklistedCharacter : configuration.submissionBlacklistedCharacters) { + if (alias.find(blacklistedCharacter) != string::npos) { + aliasInvalid = true; + ctx[MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR_BLACKLISTED_CHARACTER] = true; + break; + } + } + } + + if (!aliasInvalid && !fileName.empty()) { pqxx::connection databaseConnection(configuration.databaseConnectionString); Database::prepareStatements(databaseConnection, { ID_SELECT_FREELANCER_ID, @@ -1332,6 +1357,8 @@ int main(int argc, char *argv[]) { aliasName.append("/"); aliasName.append(alias); ctx["submissionLink"] = configuration.domain + "/commissionSubmission/" + aliasName; + string decodedFileName = fileName; + Utilities::decodeString(decodedFileName); if(Database::executePreparedStatement_INSERT_FREELANCER_FILE_SUBMISSION_ALIAS(databaseConnection, stoi(freelancerID), fileName, aliasName) > 0) ctx[MUSTACHE_FREELANCER_SUBMISSION_ALIAS_ERROR_INVALID] = true; } diff --git a/src/templateConstCollection.cpp b/src/templateConstCollection.cpp index 1e8284c..042d5c6 100644 --- a/src/templateConstCollection.cpp +++ b/src/templateConstCollection.cpp @@ -76,6 +76,7 @@ namespace TemplateConstCollection { 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_FREELANCER_SUBMISSION_ALIAS_ERROR_BLACKLISTED_CHARACTER = "SUBMISSION_ALIAS_ERROR_INVALID_BLACKLISTED_CHARACTER"; const static std::string MUSTACHE_POST_ERROR = "POST_ERROR"; const static std::string MUSTACHE_GENERIC_SEPARATOR = "#SEP#"; diff --git a/templates/freelancer_Submission_Management_View_Generate_Link.html b/templates/freelancer_Submission_Management_View_Generate_Link.html index fed2443..942203a 100644 --- a/templates/freelancer_Submission_Management_View_Generate_Link.html +++ b/templates/freelancer_Submission_Management_View_Generate_Link.html @@ -11,6 +11,9 @@ {{/COOKIE_LOGGED_IN}} {{#COOKIE_LOGGED_IN}} {{^POST_ERROR}} +

+ Forbidden Characters in the Alias Name: {{FORBIDDEN_FILE_CHARACTER_LIST_COMMA_SEPARATED}} +

Link Preview: {{domain}}/{{freelancerid}}/
diff --git a/templates/freelancer_Submission_Management_View_Generate_Link_Fulfilment.html b/templates/freelancer_Submission_Management_View_Generate_Link_Fulfilment.html index 90d073c..a60816d 100644 --- a/templates/freelancer_Submission_Management_View_Generate_Link_Fulfilment.html +++ b/templates/freelancer_Submission_Management_View_Generate_Link_Fulfilment.html @@ -25,6 +25,11 @@ Request is invalid {{/REQUEST_NOT_FILLED}} + {{#SUBMISSION_ALIAS_ERROR_INVALID_BLACKLISTED_CHARACTER}} +

+ Alias Contains Invalid characcters +
+ {{/SUBMISSION_ALIAS_ERROR_INVALID_BLACKLISTED_CHARACTER}} {{/SUBMISSION_ALIAS_ERROR}} {{/COOKIE_LOGGED_IN}} diff --git a/templates/freelancer_Submission_Management_View_Generate_link.html b/templates/freelancer_Submission_Management_View_Generate_link.html index fed2443..942203a 100644 --- a/templates/freelancer_Submission_Management_View_Generate_link.html +++ b/templates/freelancer_Submission_Management_View_Generate_link.html @@ -11,6 +11,9 @@ {{/COOKIE_LOGGED_IN}} {{#COOKIE_LOGGED_IN}} {{^POST_ERROR}} +

+ Forbidden Characters in the Alias Name: {{FORBIDDEN_FILE_CHARACTER_LIST_COMMA_SEPARATED}} +

Link Preview: {{domain}}/{{freelancerid}}/
diff --git a/templates/freelancer_Submission_Management_View_Generate_link_fulfilment.html b/templates/freelancer_Submission_Management_View_Generate_link_fulfilment.html index 90d073c..a60816d 100644 --- a/templates/freelancer_Submission_Management_View_Generate_link_fulfilment.html +++ b/templates/freelancer_Submission_Management_View_Generate_link_fulfilment.html @@ -25,6 +25,11 @@ Request is invalid {{/REQUEST_NOT_FILLED}} + {{#SUBMISSION_ALIAS_ERROR_INVALID_BLACKLISTED_CHARACTER}} +

+ Alias Contains Invalid characcters +
+ {{/SUBMISSION_ALIAS_ERROR_INVALID_BLACKLISTED_CHARACTER}} {{/SUBMISSION_ALIAS_ERROR}} {{/COOKIE_LOGGED_IN}}