Fixed issue #117. Also made changes related to events.

This commit is contained in:
Abel Hoogeveen 2018-01-16 19:37:47 +01:00
parent f5a4c9b7f4
commit 9b923bdd20
6 changed files with 21 additions and 9 deletions

View File

@ -47,8 +47,8 @@ return array(
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
*/
'csrf_protection' => true,
'csrf_token_name' => 'csrf_test_name',
'csrf_cookie_name' => 'csrf_cookie_name',
'csrf_token_name' => 'fw_csrf_token',
'csrf_cookie_name' => 'fw_csrf_cookie',
'csrf_expire' => 7200,
'csrf_regenerate' => TRUE,
'csrf_exclude_uris' => array(),

View File

@ -183,9 +183,9 @@ class Factory
$this->language = new Language();
$this->utf8 = new Utf8();
$this->uri = new URI();
$this->output = new Output();
$this->security = new Security();
$this->input = new Input();
$this->output = new Output();
$this->router = new Router();
return true;

View File

@ -166,6 +166,8 @@ class Layout
$this->assigned_variables['serverName'] = $main_config->server_name;
$this->assigned_variables['adminMail'] = $main_config->administrator_mail;
$this->assigned_variables['contact'] = $contact_config->toArray();
$this->assigned_variables['csrfTokenName'] = Factory::getInstance()->security->get_csrf_token_name();
$this->assigned_variables['csrfHash'] = Factory::getInstance()->security->get_csrf_hash();
// Select an engine if one is not already selected
if (is_null($this->current_engine)) {

View File

@ -478,10 +478,11 @@ class Logger {
/**
* Calls an HTTP error, sends it as a header, and loads a template if required to do so.
*
* @param int $errno HTTP error code
* @param bool $layout true to layout error on website
* @param int $errno HTTP error code
* @param string $message Additional message to the error
* @param bool $layout true to layout error on website
*/
public static function http_error($errno = 500, $layout = true): bool
public static function http_error($errno = 500, $message = '', $layout = true): bool
{
$http_codes = array(
400 => 'Bad Request',
@ -536,10 +537,11 @@ class Logger {
$factory = Factory::getInstance();
try {
$factory->layout->reset();
$factory->layout->assign('errorMessage', $message);
$factory->layout->display($layout);
} catch (LayoutException $exception) {
// No error page could be found, just echo the result
$factory->output->set_output("<h1>$errno</h1><h3>" . $http_codes[$errno] . '</h3>');
$factory->output->set_output("<h1>$errno</h1><h3>" . $http_codes[$errno] . '</h3><h4>' . $message . '</h4>');
}
return true;

View File

@ -364,6 +364,7 @@ class Router
if ($performLoading === true)
{
$this->routeDefault(array_values($this->uri->segments), '.*$');
return false;
}
}
@ -532,8 +533,15 @@ class Router
// Check if method exists or if there is a caller function
if (method_exists($this->callable, $event->function) || method_exists($this->callable, '__call')) {
// Run the routerCallMethodEvent
$methodEvent = Events::fireEvent('routerCallMethodEvent');
if ($methodEvent->isCancelled())
{
return;
}
// Execute the function on the controller
echo $this->callable->{$event->function}($event->parameters);
$this->output->append_output($this->callable->{$event->function}($event->parameters));
} else {
// Function could not be found
$this->logger->log('Could not find function '.$event->function.' on controller '.$event->className);

View File

@ -120,7 +120,7 @@ class Security {
*
* @var string
*/
protected $_csrf_cookie_name = 'fw_csrf_token';
protected $_csrf_cookie_name = 'fw_csrf_cookie';
/**
* List of never allowed strings