Move alias handling to utilities

This commit is contained in:
Tina_Azure
2023-04-22 23:05:21 +02:00
parent 11ecf6452e
commit fd9e02c3a0
2 changed files with 19 additions and 18 deletions

View File

@ -42,26 +42,10 @@ int main(int argc, char *argv[]) {
* Freelancer Profile listing for customers
*/
CROW_ROUTE(app, "/@<string>")
([databaseURI](string alias) {
pqxx::connection databaseConnection(databaseURI);
pqxx::result resultAlias = Database::executePreparedStatement_SELECT_ALIAS(databaseConnection, alias);
crow::json::wvalue resultJsonAlias;
([configuration](string alias) {
string redirectionHTML = "alias_Redirect.html";
if (resultAlias.size() > 0) {
resultJsonAlias = Database::convertResultRowToJSON(resultAlias);
}
else
{
//If the alias does not exist redirect back to the index.
resultJsonAlias["route"] = "/";
}
crow::mustache::context ctx(getAlias(configuration, alias));
auto page = crow::mustache::load(redirectionHTML);
crow::mustache::context ctx(resultJsonAlias);
return page.render(ctx);
});

View File

@ -252,4 +252,21 @@ namespace Utilities {
std::string hashPassword(const std::string& pwsalt, const std::string& password) {
return createHashSha512(pwsalt + password);
}
/*
* Gets The Alias
* takes configuration
* returns crow::json::wvalue with the Alias
*/
crow::json::wvalue getAlias(const Utilities::config& configuration, const std::string& alias) {
pqxx::connection databaseConnection(configuration.databaseConnectionString);
pqxx::result resultAlias = Database::executePreparedStatement_SELECT_ALIAS(databaseConnection, alias);
crow::json::wvalue resultJsonAlias;
if (!resultAlias.empty())
resultJsonAlias = Database::convertResultRowToJSON(resultAlias);
else
resultJsonAlias["route"] = "/"; //If the alias does not exist redirect back to the index.
return resultJsonAlias;
}
}