implement freelancer alias base management page

and minor fixes
This commit is contained in:
Tina_Azure 2023-05-19 18:06:14 +02:00
parent 1620967c45
commit d83b427857
7 changed files with 93 additions and 6 deletions

View File

@ -452,6 +452,16 @@ namespace Database {
return result;
}
/*
* Executes the prepared statement SELECT_FREELANCER_ALIAS
* Takes an open pqxx::connection and the freelancer email to select by
*/
pqxx::result executePreparedStatement_SELECT_FREELANCER_ALIAS(pqxx::connection &connection, const std::string& freelancerEmail) {
pqxx::work work(connection);
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_FREELANCER_ALIAS, freelancerEmail);
work.commit();
return result;
}
/*
* Executes the prepared statement UPDATE_LOGIN_VALIDATION_KEY
* Takes an open pqxx::connection, the freelancerID and the loginKey to update the entry

View File

@ -100,6 +100,12 @@ namespace DatabaseStatementConstCollection {
const static std::string PREPARED_STATEMENT_SELECT_ALIAS = "selectAlias";
const static std::string SQL_STATEMENT_SELECT_ALIAS = "select aliasname, route, routeparameter, routevalue from aliasroutes where aliasname = $1;";
/*
* Name and Statement for prepared statement to select an alias and its route via the alias name
*/
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);";
/*
* Name and Statement for prepared statement to update the loginvalidationkey of a freelancer via the freelancerID
*/
@ -125,7 +131,7 @@ namespace DatabaseStatementConstCollection {
const static std::string SQL_STATEMENT_SELECT_FREELANCER_EMAIL_FROM_PASSWORD_RESET_KEY = "select freelanceremail from passwordresetkeys where passwordresetkey = $1;";
/*
* Name and Statement for prepared statement to check if an reset key is expired
* Name and Statement for prepared statement to check if a reset key is expired
* returns 0 if key not expired
*/
const static std::string PREPARED_STATEMENT_SELECT_CHECK_FREELANCER_RESET_KEY_EXPIRED = "checkFreelancerResetKeyExpired";
@ -240,6 +246,7 @@ namespace DatabaseStatementConstCollection {
const static int ID_INSERT_FREELANCER_TEMPLATE = 29;
const static int ID_DELETE_FREELANCER_TEMPLATE = 30;
const static int ID_UPDATE_EDIT_FREELANCER_TEMPLATE = 31;
const static int ID_SELECT_FREELANCER_ALIAS = 32;
/*
* Easy access to prepared statements via prepared statement name
@ -276,7 +283,8 @@ namespace DatabaseStatementConstCollection {
{PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT, SQL_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT},
{PREPARED_STATEMENT_INSERT_FREELANCER_TEMPLATE, SQL_STATEMENT_INSERT_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},
};
/*
* Easy access to prepared statement name via int
@ -313,7 +321,8 @@ namespace DatabaseStatementConstCollection {
{ID_UPDATE_EXPIRATION_LOGIN_LOCK_OUT, PREPARED_STATEMENT_UPDATE_EXPIRATION_LOGIN_LOCK_OUT},
{ID_INSERT_FREELANCER_TEMPLATE, PREPARED_STATEMENT_INSERT_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},
};
/*

View File

@ -71,7 +71,7 @@ int main(int argc, char *argv[]) {
*/
CROW_ROUTE(app, "/@<string>")
([configuration](string alias) {
crow::mustache::context ctx(getAlias(configuration, alias));
crow::mustache::context ctx(Utilities::getAlias(configuration, alias));
auto page = crow::mustache::load(TEMPLATE_ALIAS_REDIRECT);
return page.render(ctx);
});
@ -771,7 +771,6 @@ int main(int argc, char *argv[]) {
/*
* Execute Template Operation
* todo:implement
*/
CROW_ROUTE(app, "/freelancer/templateManagement/fulfilment/<string>").methods("POST"_method)
([&, configuration](const crow::request& postRequest, string operation ) {
@ -855,6 +854,22 @@ int main(int argc, char *argv[]) {
return page.render(ctx);
});
/*
* Page for freelancer to create/delete Alias
*/
CROW_ROUTE(app, "/freelancer/aliasManagement")
([&, configuration](const crow::request& getRequest ) {
auto& cookieCtx = app.get_context<crow::CookieParser>(getRequest);
crow::mustache::context ctx;
if (Utilities::checkCookieLoginState(configuration, cookieCtx)) {
ctx = Utilities::getFreelancerAlias(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(TEMPLATE_FREELANCER_ALIAS_MANAGEMENT);
return page.render(ctx);
});

View File

@ -29,6 +29,7 @@ namespace TemplateConstCollection {
const static std::string TEMPLATE_FREELANCER_TEMPLATE_MANAGEMENT_FULFILMENT_STAGE_EXECUTION = "freelancer_Template_Management_Fulfilment_Stage_Execution.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_ALIAS_MANAGEMENT = "freelancer_Alias_Management.html";
//Mustache Error/Success variable names
const static std::string MUSTACHE_ERROR_COMMISSIONS_CLOSED = "ERROR_COMMISSIONS_CLOSED";

View File

@ -523,6 +523,19 @@ namespace Utilities {
return resultJsonFreelancerTemplate;
}
/*
* Gets the freelancer alias and converts them into a wvalue JSON under the name "alias"
* takes config and freelancer email
*/
crow::json::wvalue getFreelancerAlias(const Utilities::config& configuration, const std::string& emailAddress) {
crow::json::wvalue resultJsonFreelancerAlias;
pqxx::connection databaseConnection(configuration.databaseConnectionString);
Database::prepareStatement(databaseConnection, ID_SELECT_FREELANCER_ALIAS);
pqxx::result aliasResult = Database::executePreparedStatement_SELECT_FREELANCER_ALIAS(databaseConnection, emailAddress);
resultJsonFreelancerAlias = Database::convertResultToJSON(aliasResult, "alias");
return resultJsonFreelancerAlias;
}
/*
* Checks if a given string is a valid number
*/

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
{{> templateIncludes/style.css.html}}
</head>
<body>
{{^COOKIE_LOGGED_IN}}
Please Log in.
{{/COOKIE_LOGGED_IN}}
{{#COOKIE_LOGGED_IN}}
<h2>Freelancer: {{freelanceremail}}</h2>
<br>
<br>
<table>
{{#alias}}
<tr>
<th>@{{aliasname}}</th>
<th>{{route}}</th>
<th>
<form action="/freelancer/aliasManagement/delete" method="post">
<button type="submit" name="alias" value="{{aliasname}}" class="button">Delete</button>
</form>
</th>
</tr>
{{/alias}}
</table>
<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>

View File

@ -28,7 +28,7 @@
<form action="/freelancer/settings" method="get">
<button type="submit" class="button">Change Account Settings</button>
</form>
<form action="/freelancer/aliasSetup" method="get">
<form action="/freelancer/aliasManagement" method="get">
<button type="submit" class="button">Create/Remove Alias</button>
</form>
</div>