Redirection template
Handle @alias via the redirection template
This commit is contained in:
@ -48,6 +48,12 @@ namespace Database {
|
|||||||
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES = "selectFreelancerTemplates";
|
const static std::string PREPARED_STATEMENT_SELECT_FREELANCER_TEMPLATES = "selectFreelancerTemplates";
|
||||||
const static std::string SQL_STATEMENT_SELECT_FREELANCER_TEMPLATES = "select id, name, content from templates where freelancerid = $1 order by id;";
|
const static std::string SQL_STATEMENT_SELECT_FREELANCER_TEMPLATES = "select id, name, content from templates where freelancerid = $1 order by id;";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Name and Statement for prepared statement to select an alias and its route via the alias name
|
||||||
|
*/
|
||||||
|
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;";
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Selects freelancers, their basicInfo and if the commissions are closed/open ordered by name.
|
* Selects freelancers, their basicInfo and if the commissions are closed/open ordered by name.
|
||||||
* Delivers if the commission limit has been reached and if the commissions are closed based on the accepted/completed state of the freelancers requests
|
* Delivers if the commission limit has been reached and if the commissions are closed based on the accepted/completed state of the freelancers requests
|
||||||
@ -180,6 +186,18 @@ namespace Database {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Executes the prepared statement SELECT_ALIAS
|
||||||
|
* Takes an open pqxx::connection and the alias name to select by
|
||||||
|
*/
|
||||||
|
pqxx::result executePreparedStatement_SELECT_ALIAS(pqxx::connection &connection, std::string aliasName) {
|
||||||
|
connection.prepare(PREPARED_STATEMENT_SELECT_ALIAS, SQL_STATEMENT_SELECT_ALIAS);
|
||||||
|
pqxx::work work(connection);
|
||||||
|
pqxx::result result = work.exec_prepared(PREPARED_STATEMENT_SELECT_ALIAS, aliasName);
|
||||||
|
work.commit();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
29
src/main.cpp
29
src/main.cpp
@ -25,7 +25,7 @@ int main() {
|
|||||||
/*
|
/*
|
||||||
* Freelancer Profile listing for customers
|
* Freelancer Profile listing for customers
|
||||||
*/
|
*/
|
||||||
CROW_ROUTE(app, "/").methods("POST"_method)
|
CROW_ROUTE(app, "/").methods("POST"_method, "GET"_method)
|
||||||
([databaseURI]() {
|
([databaseURI]() {
|
||||||
pqxx::connection databaseConnection(databaseURI);
|
pqxx::connection databaseConnection(databaseURI);
|
||||||
pqxx::result result = Database::executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(databaseConnection);
|
pqxx::result result = Database::executeStatement_SELECT_FREELANCERS_WITHCOMMISSIONSSTATE(databaseConnection);
|
||||||
@ -37,6 +37,33 @@ int main() {
|
|||||||
return page.render(ctx);
|
return page.render(ctx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
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"] = "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
auto page = crow::mustache::load(redirectionHTML);
|
||||||
|
crow::mustache::context ctx(resultJsonAlias);
|
||||||
|
|
||||||
|
return page.render(ctx);
|
||||||
|
});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Freelancer Profile Page for customers
|
* Freelancer Profile Page for customers
|
||||||
*/
|
*/
|
||||||
|
45
templates/alias_Redirect.html
Normal file
45
templates/alias_Redirect.html
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
table {
|
||||||
|
font-family: arial, sans-serif;
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
border: 1px solid #dddddd;
|
||||||
|
text-align: left;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
tr:nth-child(even) {
|
||||||
|
background-color: #dddddd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Redirecting:</h1>
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
function formAutoSubmit () {
|
||||||
|
var frm = document.getElementById("redirectBtn");
|
||||||
|
frm.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.onload = formAutoSubmit;
|
||||||
|
|
||||||
|
</script>
|
||||||
|
<form action="/" method="post">
|
||||||
|
<button type="submit" class="button">Return to freelancer selection</button>
|
||||||
|
</form>
|
||||||
|
<form id="redirectForm" action="{{route}}" method="post">
|
||||||
|
<button id="redirectBtn" type="submit" name="{{routeparameter}}" value="{{routevalue}}" class="button">Redirecting to: {{route}}</button>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user