implement freelancer alias deletion

This commit is contained in:
Tina_Azure 2023-05-19 18:10:31 +02:00
parent d83b427857
commit bfddfd5271
6 changed files with 83 additions and 0 deletions

View File

@ -462,6 +462,18 @@ namespace Database {
work.commit(); work.commit();
return result; return result;
} }
/*
* Executes the prepared statement DELETE_FREELANCER_ALIAS
* Deletes the entry for a reset key based on a freelancer email and the alias name
* Takes an open pqxx::connection and the freelancers email
*/
void executePreparedStatement_DELETE_FREELANCER_ALIAS(pqxx::connection &connection, const std::string& aliasName, const std::string& freelancerEmail) {
pqxx::work work(connection);
work.exec_prepared(PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS, aliasName, freelancerEmail);
work.commit();
}
/* /*
* Executes the prepared statement UPDATE_LOGIN_VALIDATION_KEY * Executes the prepared statement UPDATE_LOGIN_VALIDATION_KEY
* Takes an open pqxx::connection, the freelancerID and the loginKey to update the entry * Takes an open pqxx::connection, the freelancerID and the loginKey to update the entry

View File

@ -106,6 +106,11 @@ namespace DatabaseStatementConstCollection {
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS = "selectFreelancerAlias"; const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS = "selectFreelancerAlias";
const static std::string SQL_STATEMENT_SELECT_FREELANCER_ALIAS = "select aliasname, route from aliasroutes where freelancerid = (select freelancers.id from freelancers where emailaddress = $1);"; const static std::string SQL_STATEMENT_SELECT_FREELANCER_ALIAS = "select aliasname, route from aliasroutes where freelancerid = (select freelancers.id from freelancers where emailaddress = $1);";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
const static std::string PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS = "deleteFreelancerAlias";
const static std::string SQL_STATEMENT_DELETE_FREELANCER_ALIAS = "delete from aliasroutes where aliasname = $1 and freelancerid = (select freelancers.id from freelancers where emailaddress = $2);";
/* /*
* Name and Statement for prepared statement to update the loginvalidationkey of a freelancer via the freelancerID * Name and Statement for prepared statement to update the loginvalidationkey of a freelancer via the freelancerID
*/ */
@ -247,6 +252,7 @@ namespace DatabaseStatementConstCollection {
const static int ID_DELETE_FREELANCER_TEMPLATE = 30; const static int ID_DELETE_FREELANCER_TEMPLATE = 30;
const static int ID_UPDATE_EDIT_FREELANCER_TEMPLATE = 31; const static int ID_UPDATE_EDIT_FREELANCER_TEMPLATE = 31;
const static int ID_SELECT_FREELANCER_ALIAS = 32; const static int ID_SELECT_FREELANCER_ALIAS = 32;
const static int ID_DELETE_FREELANCER_ALIAS = 33;
/* /*
* Easy access to prepared statements via prepared statement name * Easy access to prepared statements via prepared statement name
@ -285,6 +291,7 @@ namespace DatabaseStatementConstCollection {
{PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE, SQL_STATEMENT_DELETE_FREELANCER_TEMPLATE}, {PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE, SQL_STATEMENT_DELETE_FREELANCER_TEMPLATE},
{PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE, SQL_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE}, {PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE, SQL_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE},
{PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS, SQL_STATEMENT_SELECT_FREELANCER_ALIAS}, {PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS, SQL_STATEMENT_SELECT_FREELANCER_ALIAS},
{PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS, SQL_STATEMENT_DELETE_FREELANCER_ALIAS},
}; };
/* /*
* Easy access to prepared statement name via int * Easy access to prepared statement name via int
@ -323,6 +330,7 @@ namespace DatabaseStatementConstCollection {
{ID_DELETE_FREELANCER_TEMPLATE, PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE}, {ID_DELETE_FREELANCER_TEMPLATE, PREPARED_STATEMENT_DELETE_FREELANCER_TEMPLATE},
{ID_UPDATE_EDIT_FREELANCER_TEMPLATE, PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE}, {ID_UPDATE_EDIT_FREELANCER_TEMPLATE, PREPARED_STATEMENT_UPDATE_EDIT_FREELANCER_TEMPLATE},
{ID_SELECT_FREELANCER_ALIAS, PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS}, {ID_SELECT_FREELANCER_ALIAS, PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS},
{ID_DELETE_FREELANCER_ALIAS, PREPARED_STATEMENT_DELETE_FREELANCER_ALIAS},
}; };
/* /*

View File

@ -870,6 +870,31 @@ int main(int argc, char *argv[]) {
return page.render(ctx); return page.render(ctx);
}); });
/*
* Execute Alias deletion
*/
CROW_ROUTE(app, "/freelancer/aliasManagement/delete").methods("POST"_method)
([&, configuration](const crow::request& postRequest) {
auto& cookieCtx = app.get_context<crow::CookieParser>(postRequest);
crow::mustache::context ctx;
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
string postRequestBody = postRequest.body;
Utilities::decodeString(postRequestBody);
string aliasName;
vector<string> splitPostRequestBody = Utilities::splitStringIntoVector(postRequestBody, '&');
for (const string& item : splitPostRequestBody) {
vector<string> splitItem = Utilities::splitStringIntoVector(item, '=');
if (splitItem.at(0) == "alias")
aliasName = splitItem.at(1);
}
Utilities::deleteFreelancerAlias(configuration, aliasName, 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(TEMPLATE_FREELANCER_ALIAS_MANAGEMENT_DELETE);
return page.render(ctx);
});

View File

@ -30,6 +30,7 @@ namespace TemplateConstCollection {
const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_CREATE_NEW = "freelancer_Template_Management_Create_New.html"; const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_CREATE_NEW = "freelancer_Template_Management_Create_New.html";
const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_CREATE_NEW_FULFILMENT = "freelancer_Template_Management_Create_New_Fulfilment.html"; const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_CREATE_NEW_FULFILMENT = "freelancer_Template_Management_Create_New_Fulfilment.html";
const static std::string TEMPLATE_FREELANCER_ALIAS_MANAGEMENT = "freelancer_Alias_Management.html"; const static std::string TEMPLATE_FREELANCER_ALIAS_MANAGEMENT = "freelancer_Alias_Management.html";
const static std::string TEMPLATE_FREELANCER_ALIAS_MANAGEMENT_DELETE = "freelancer_Alias_Management_Delete.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";

View File

@ -536,6 +536,15 @@ namespace Utilities {
return resultJsonFreelancerAlias; return resultJsonFreelancerAlias;
} }
/*
* Deletes a freelancers alias
* takes config the alias name and the freelancers email
*/
void deleteFreelancerAlias(const Utilities::config& configuration, const std::string& aliasName, const std::string& emailAddress) {
pqxx::connection databaseConnection(configuration.databaseConnectionString);
Database::prepareStatement(databaseConnection, ID_DELETE_FREELANCER_ALIAS);
Database::executePreparedStatement_DELETE_FREELANCER_ALIAS(databaseConnection, aliasName, emailAddress);
}
/* /*
* Checks if a given string is a valid number * Checks if a given string is a valid number
*/ */

View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
{{> templateIncludes/style.css.html}}
</head>
<body>
{{^COOKIE_LOGGED_IN}}
Please Log in.
{{/COOKIE_LOGGED_IN}}
{{#COOKIE_LOGGED_IN}}
Operation concluded:
<br>
<form action="/freelancer/aliasManagement" method="get">
<button type="submit" class="button">Return to Alias Managment</button>
</form>
<form action="/freelancer/aliasManagement/new" method="get">
<button type="submit" class="button">Create New Alias Route</button>
</form>
{{/COOKIE_LOGGED_IN}}
{{> templateIncludes/freelancerLoginSignupProfileLogoutInterface.html.html}}
<br>
{{> templateIncludes/returnToIndexButton.html.html}}
</body>
</html>