Skip to content

Commit

Permalink
Fix CSRF Token
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhicetea committed Jun 27, 2016
1 parent 19ae022 commit 4d3b1fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Sifoni/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ public function isFormValid($action = '', $token_name = '_token')
{
$token = new CsrfToken($action, $this->request->get($token_name));

return $this->app['form.csrf_provider']->isTokenValid($token);
return $this->app['csrf.token_manager']->isTokenValid($token);
}
}
13 changes: 13 additions & 0 deletions src/Sifoni/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Sifoni\Provider\SessionServiceProvider;
use Sifoni\Provider\HttpCacheServiceProvider;
use Monolog\Logger;
use Twig_SimpleFunction;
use Twig_Environment;

class Engine
{
Expand Down Expand Up @@ -188,6 +190,17 @@ private function registerServices()

if ($app['enabled_csrf']) {
$app->register(new CsrfServiceProvider());

if ($app['enabled_twig']) {
$app['twig'] = $app->extend('twig', function (Twig_Environment $twig, $app) {
$csrf_token = new Twig_SimpleFunction('csrf_token', function ($token_id) use ($app) {
return $app['csrf.token_manager']->getToken($token_id);
});
$twig->addFunction($csrf_token);

return $twig;
});
}
}

if ($app['enabled_capsule']) {
Expand Down

0 comments on commit 4d3b1fd

Please sign in to comment.