Adjust to new Template::getPage() returning value, not reference

This commit is contained in:
Albert S. 2021-10-08 00:11:58 +02:00
parent 8ffa64beea
commit 828d827c3d
11 changed files with 13 additions and 12 deletions

View File

@ -34,7 +34,7 @@ void Handler::setGeneralVars(TemplatePage &page)
} }
Response Handler::errorResponse(std::string errortitle, std::string errormessage, int status) Response Handler::errorResponse(std::string errortitle, std::string errormessage, int status)
{ {
TemplatePage &error = this->templ->getPage("error"); TemplatePage error = this->templ->getPage("error");
error.setVar("title", createPageTitle(errortitle)); error.setVar("title", createPageTitle(errortitle));
error.setVar("errortitle", errortitle); error.setVar("errortitle", errortitle);
error.setVar("errormessage", errormessage); error.setVar("errormessage", errormessage);

View File

@ -32,7 +32,7 @@ Response HandlerAllCategories::handleRequest(const Request &r)
"No categories", "No categories",
"This wiki does not have any categories defined yet or your query options did not yield any results"); "This wiki does not have any categories defined yet or your query options did not yield any results");
} }
TemplatePage &searchPage = this->templ->getPage("allcategories"); TemplatePage searchPage = this->templ->getPage("allcategories");
std::string body = std::string body =
this->templ->renderSearch(resultList, [&](std::string str) { return this->urlProvider->category(str); }); this->templ->renderSearch(resultList, [&](std::string str) { return this->urlProvider->category(str); });
searchPage.setVar("categorylist", body); searchPage.setVar("categorylist", body);

View File

@ -32,7 +32,7 @@ Response HandlerAllPages::handleRequest(const Request &r)
{ {
return errorResponse("No pages", "This wiki does not have any pages yet"); return errorResponse("No pages", "This wiki does not have any pages yet");
} }
TemplatePage &searchPage = this->templ->getPage("allpages"); TemplatePage searchPage = this->templ->getPage("allpages");
std::string body = this->templ->renderSearch(resultList); std::string body = this->templ->renderSearch(resultList);
searchPage.setVar("pagelist", body); searchPage.setVar("pagelist", body);
searchPage.setVar("title", createPageTitle("All pages")); searchPage.setVar("title", createPageTitle("All pages"));

View File

@ -33,7 +33,7 @@ Response HandlerCategory::handleRequest(const Request &r)
} }
QueryOption qo = queryOption(r); QueryOption qo = queryOption(r);
auto resultList = categoryDao->fetchMembers(categoryname, qo); auto resultList = categoryDao->fetchMembers(categoryname, qo);
TemplatePage &searchPage = this->templ->getPage("show_category"); TemplatePage searchPage = this->templ->getPage("show_category");
std::string body = this->templ->renderSearch(resultList); std::string body = this->templ->renderSearch(resultList);
searchPage.setVar("pagelist", body); searchPage.setVar("pagelist", body);
searchPage.setVar("categoryname", categoryname); searchPage.setVar("categoryname", categoryname);

View File

@ -55,7 +55,7 @@ Response HandlerLogin::handleRequest(const Request &r)
{ {
page = "index"; page = "index";
} }
TemplatePage &loginTemplatePage = this->templ->getPage("login"); TemplatePage loginTemplatePage = this->templ->getPage("login");
setGeneralVars(loginTemplatePage); setGeneralVars(loginTemplatePage);
loginTemplatePage.setVar("loginurl", urlProvider->login(page)); loginTemplatePage.setVar("loginurl", urlProvider->login(page));
loginTemplatePage.setVar("title", createPageTitle("Login")); loginTemplatePage.setVar("title", createPageTitle("Login"));

View File

@ -63,8 +63,9 @@ void HandlerPage::setPageVars(TemplatePage &page, std::string pagename)
if(!pagename.empty()) if(!pagename.empty())
{ {
std::string headerlinks; std::string headerlinks;
TemplatePage &headerlink = this->templ->getPage("_headerlink"); TemplatePage headerlink = this->templ->getPage("_headerlink");
auto addHeaderLink = [&headerlinks, &headerlink](std::string href, std::string value) { auto addHeaderLink = [&headerlinks, &headerlink](std::string href, std::string value)
{
headerlink.setVar("href", href); headerlink.setVar("href", href);
headerlink.setVar("value", value); headerlink.setVar("value", value);
headerlinks += headerlink.render(); headerlinks += headerlink.render();

View File

@ -121,7 +121,7 @@ Response HandlerPageEdit::handleRequest(PageDao &pageDao, std::string pagename,
} }
} }
TemplatePage &templatePage = this->templ->getPage("page_creation"); TemplatePage templatePage = this->templ->getPage("page_creation");
templatePage.setVar("actionurl", urlProvider->editPage(pagename)); templatePage.setVar("actionurl", urlProvider->editPage(pagename));
templatePage.setVar("content", body); templatePage.setVar("content", body);
setPageVars(templatePage, pagename); setPageVars(templatePage, pagename);

View File

@ -128,7 +128,7 @@ Response HandlerPageView::handleRequest(PageDao &pageDao, std::string pagename,
return errorResponse("Database error", "While trying to fetch revision, a database error occured"); return errorResponse("Database error", "While trying to fetch revision, a database error occured");
} }
TemplatePage &page = this->templ->getPage(templatepartname); TemplatePage page = this->templ->getPage(templatepartname);
Parser parser; Parser parser;
Response result; Response result;

View File

@ -37,7 +37,7 @@ Response HandlerSearch::handleRequest(const Request &r)
{ {
return errorResponse("No results", "Your search for " + q + " did not yield any results."); return errorResponse("No results", "Your search for " + q + " did not yield any results.");
} }
TemplatePage &searchPage = this->templ->getPage("search"); TemplatePage searchPage = this->templ->getPage("search");
std::string body = this->templ->renderSearch(resultList); std::string body = this->templ->renderSearch(resultList);
searchPage.setVar("pagelist", body); searchPage.setVar("pagelist", body);
searchPage.setVar("searchterm", q); searchPage.setVar("searchterm", q);

View File

@ -51,7 +51,7 @@ Response HandlerUserSettings::handleRequest(const Request &r)
} }
} }
TemplatePage &userSettingsPage = this->templ->getPage("usersettings"); TemplatePage userSettingsPage = this->templ->getPage("usersettings");
setGeneralVars(userSettingsPage); setGeneralVars(userSettingsPage);
userSettingsPage.setVar("usersettingsurl", urlProvider->userSettings()); userSettingsPage.setVar("usersettingsurl", urlProvider->userSettings());
userSettingsPage.setVar("title", createPageTitle("User settings - " + this->userSession->user.login)); userSettingsPage.setVar("title", createPageTitle("User settings - " + this->userSession->user.login));

View File

@ -59,7 +59,7 @@ Response RequestWorker::processRequest(const Request &r)
if(session.loggedIn && session.csrf_token != r.post("csrf_token")) if(session.loggedIn && session.csrf_token != r.post("csrf_token"))
{ {
// TODO: this is code duplication // TODO: this is code duplication
TemplatePage &error = this->templ->getPage("error"); TemplatePage error = this->templ->getPage("error");
error.setVar("errortitle", "Invalid csrf token"); error.setVar("errortitle", "Invalid csrf token");
error.setVar("errormessage", "Invalid csrf token"); error.setVar("errormessage", "Invalid csrf token");
return {403, error.render()}; return {403, error.render()};