Move alias handling to utilities
This commit is contained in:
20
src/main.cpp
20
src/main.cpp
@ -42,26 +42,10 @@ int main(int argc, char *argv[]) {
|
|||||||
* Freelancer Profile listing for customers
|
* Freelancer Profile listing for customers
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/@<string>")
|
CROW_ROUTE(app, "/@<string>")
|
||||||
([databaseURI](string alias) {
|
([configuration](string alias) {
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
|
||||||
pqxx::result resultAlias = Database::executePreparedStatement_SELECT_ALIAS(databaseConnection, alias);
|
|
||||||
|
|
||||||
crow::json::wvalue resultJsonAlias;
|
|
||||||
|
|
||||||
string redirectionHTML = "alias_Redirect.html";
|
string redirectionHTML = "alias_Redirect.html";
|
||||||
|
crow::mustache::context ctx(getAlias(configuration, alias));
|
||||||
if (resultAlias.size() > 0) {
|
|
||||||
resultJsonAlias = Database::convertResultRowToJSON(resultAlias);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//If the alias does not exist redirect back to the index.
|
|
||||||
resultJsonAlias["route"] = "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
auto page = crow::mustache::load(redirectionHTML);
|
auto page = crow::mustache::load(redirectionHTML);
|
||||||
crow::mustache::context ctx(resultJsonAlias);
|
|
||||||
|
|
||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -252,4 +252,21 @@ namespace Utilities {
|
|||||||
std::string hashPassword(const std::string& pwsalt, const std::string& password) {
|
std::string hashPassword(const std::string& pwsalt, const std::string& password) {
|
||||||
return createHashSha512(pwsalt + 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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user