korotovsky/csrf-validator-bundle

Validate CSRF token via annotation

0.4.2 2016-12-22 08:25 UTC

This package is not auto-updated.

Last update: 2024-11-15 22:04:30 UTC


README

  • PHP >=5.5
  • KrtvCsrfValidatorBundle's 0.4.x compatible with symfony (>=2.7 versions).
  • Doctrine is required

Features:

  • Add extra annotation for auto validation CSRF-tokens to your controller actions

Installation and configuration:

Pretty simple with Composer, add:

{
    "require": {
        "korotovsky/csrf-validator-bundle": "0.4.*"
    }
}

For latest version (UNSTABLE) use

{
    "require": {
        "korotovsky/csrf-validator-bundle": "~0.4.0@dev"
    }
}

Configuration example

  • No specific configuration is needed!

Add KrtvCsrfValidatorBundle to your application kernel

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Krtv\Bundle\CsrfValidatorBundle\KrtvCsrfValidatorBundle(),
        // ...
    );
}

Usage examples:

Just add annotation to your controller action

// Acme\MainBundle\Controller\DefaultController.php

use Krtv\Bundle\CsrfValidatorBundle\Annotations as Krtv;

/**
 * @Krtv\Csrf(intention="your_intention")
 * @return Response
 */
public function importantZoneAction()
{
    // some code here ...

    return new Response();
}

View

<a href="{{ path('_some_route', {'token': csrf_token('your_intention')}) }}">Subscribe!</a>