Browse Source

updated CSRF step to be a step for the global secret

Fabien Potencier 14 years ago
parent
commit
76dd33968e
4 changed files with 2 additions and 147 deletions
  1. 0 28
      Form/CsrfStepType.php
  2. 0 44
      Resources/views/Step/csrf.html.twig
  3. 0 73
      Step/CsrfStep.php
  4. 2 2
      SymfonyWebConfiguratorBundle.php

+ 0 - 28
Form/CsrfStepType.php

@@ -1,28 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\WebConfiguratorBundle\Form;
-
-use Symfony\Component\Form\AbstractType;
-use Symfony\Component\Form\FormBuilder;
-
-/**
- * CSRF Form Type.
- *
- * @author Marc Weistroff <marc.weistroff@sensio.com>
- */
-class CsrfStepType extends AbstractType
-{
-    public function buildForm(FormBuilder $builder, array $options)
-    {
-        $builder->add('csrf_secret', 'text');
-    }
-}

+ 0 - 44
Resources/views/Step/csrf.html.twig

@@ -1,44 +0,0 @@
-{% extends "SymfonyWebConfiguratorBundle::layout.html.twig" %}
-
-{% block title %}Symfony - Configure CSRF{% endblock %}
-
-{% block content %}
-    {% form_theme form "SymfonyWebConfiguratorBundle::form.html.twig" %}
-    {% include "SymfonyWebConfiguratorBundle::steps.html.twig" with { "index": index, "count": count } %}
-
-    <h1>CSRF Protection</h1>
-    <p>Configure CSRF protection for your website :</p>
-
-    {{ form_errors(form) }}
-    <form action="{{ path('_configurator_step', { 'index': index }) }} " method="POST">
-        <div class="symfony-form-row">
-            {{ form_label(form.csrf_secret) }}
-            <div class="symfony-form-field">
-                {{ form_widget(form.csrf_secret) }}
-                <a class="symfony-button-grey" href="#" onclick="generateCsrf(); return false;">Generate</a>
-                <div class="symfony-form-errors">
-                    {{ form_errors(form.csrf_secret) }}
-                </div>
-            </div>
-        </div>
-
-        {{ form_rest(form) }}
-
-        <div class="symfony-form-footer">
-            <p><input type="submit" value="Next Step" class="symfony-button-grey" /></p>
-            <p>* mandatory fields</p>
-        </div>
-
-    </form>
-
-    <script type="text/javascript">
-        function generateCsrf()
-        {
-            var result = '';
-            for (i=0; i < 32; i++) {
-                result += Math.round(Math.random()*16).toString(16);
-            }
-            document.getElementById('csrfstep_csrf_secret').value = result;
-        }
-    </script>
-{% endblock %}

+ 0 - 73
Step/CsrfStep.php

@@ -1,73 +0,0 @@
-<?php
-
-/*
- * This file is part of the Symfony package.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Symfony\Bundle\WebConfiguratorBundle\Step;
-
-use Symfony\Bundle\WebConfiguratorBundle\Exception\StepRequirementException;
-use Symfony\Bundle\WebConfiguratorBundle\Form\CsrfStepType;
-
-/**
- * Csrf Step.
- *
- * @author Fabien Potencier <fabien@symfony.com>
- */
-class CsrfStep implements StepInterface
-{
-    /**
-     * @assert:NotBlank
-     */
-    public $csrf_secret;
-
-    public function __construct(array $parameters)
-    {
-        $this->csrf_secret = $parameters['csrf_secret'];
-    }
-
-    /**
-     * @see StepInterface
-     */
-    public function getFormType()
-    {
-        return new CsrfStepType();
-    }
-
-    /**
-     * @see StepInterface
-     */
-    public function checkRequirements()
-    {
-        return array();
-    }
-
-    /**
-     * checkOptionalSettings
-     */
-    public function checkOptionalSettings()
-    {
-        return array();
-    }
-
-    /**
-     * @see StepInterface
-     */
-    public function update(StepInterface $data)
-    {
-        return array('csrf_secret' => $data->csrf_secret);
-    }
-
-    /**
-     * @see StepInterface
-     */
-    public function getTemplate()
-    {
-        return 'SymfonyWebConfiguratorBundle:Step:csrf.html.twig';
-    }
-}

+ 2 - 2
SymfonyWebConfiguratorBundle.php

@@ -13,7 +13,7 @@ namespace Symfony\Bundle\WebConfiguratorBundle;
 
 use Symfony\Component\HttpKernel\Bundle\Bundle;
 use Symfony\Bundle\WebConfiguratorBundle\Step\DoctrineStep;
-use Symfony\Bundle\WebConfiguratorBundle\Step\CsrfStep;
+use Symfony\Bundle\WebConfiguratorBundle\Step\SecretStep;
 
 /**
  * SymfonyWebConfiguratorBundle.
@@ -27,6 +27,6 @@ class SymfonyWebConfiguratorBundle extends Bundle
     {
         $configurator = $this->container->get('symfony.webconfigurator');
         $configurator->addStep(new DoctrineStep($configurator->getParameters()));
-        $configurator->addStep(new CsrfStep($configurator->getParameters()));
+        $configurator->addStep(new SecretStep($configurator->getParameters()));
     }
 }