Skip to content

Instantly share code, notes, and snippets.

@rande
Created June 18, 2010 14:26
Show Gist options
  • Save rande/443693 to your computer and use it in GitHub Desktop.
Save rande/443693 to your computer and use it in GitHub Desktop.
automatically redirect a user when a csrf token is detected
$this->dispatcher->connect('form.validation_error', function(sfEvent $event) {
$form = $event->getSubject();
$error = $event['error'];
if(!$form->isCSRFProtected())
{
return;
}
$field_name = sfForm::getCSRFFieldName();
if(isset($error[$field_name]))
{
if(sfContext::hasInstance())
{
$context = sfContext::getInstance();
$context->getController()->redirect('@homepage');
$context->getUser()->setFlash('notice', 'Session réinitialisée : vous êtes redirigé vers la page d\'accueil, car votre session a expiré.');
throw new sfStopException();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment