Fix session locking issue after refactoring routing

This commit is contained in:
Dale Davies
2022-07-19 12:27:20 +01:00
parent 2d0d7c89fb
commit 74c2fe882a
2 changed files with 9 additions and 8 deletions

View File

@@ -23,6 +23,9 @@ class Main {
$this->router = new RouteList;
// Set up the routes that Jump expects.
$this->router->addRoute('/', [
'class' => 'Jump\Pages\HomePage'
]);
$this->router->addRoute('/tag/<tag>', [
'class' => 'Jump\Pages\TagPage'
]);
@@ -46,14 +49,6 @@ class Main {
$this->session->setName($this->config->get('sessionname'));
$this->session->setExpiration($this->config->get('sessiontimeout'));
// Get a Nette session section for CSRF data.
$csrfsection = $this->session->getSection('csrf');
// Create a new CSRF token within the section if one doesn't exist already.
if (!$csrfsection->offsetExists('token')){
$csrfsection->set('token', bin2hex(random_bytes(32)));
}
// Try to match the correct route based on the HTTP request.
$matchedroute = $this->router->match($this->request);

View File

@@ -28,6 +28,12 @@ abstract class AbstractPage {
return urlencode($renderer($text));
}),
]);
// Get a Nette session section for CSRF data.
$csrfsection = $this->session->getSection('csrf');
// Create a new CSRF token within the section if one doesn't exist already.
if (!$csrfsection->offsetExists('token')){
$csrfsection->set('token', bin2hex(random_bytes(32)));
}
}
abstract protected function render_content(): string;