فهرست منبع

added missing files

Fabien Potencier 14 سال پیش
والد
کامیت
3c272a6cef
3فایلهای تغییر یافته به همراه149 افزوده شده و 0 حذف شده
  1. 28 0
      Form/SecretStepType.php
  2. 44 0
      Resources/views/Step/secret.html.twig
  3. 77 0
      Step/SecretStep.php

+ 28 - 0
Form/SecretStepType.php

@@ -0,0 +1,28 @@
+<?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;
+
+/**
+ * Secret Form Type.
+ *
+ * @author Marc Weistroff <marc.weistroff@sensio.com>
+ */
+class SecretStepType extends AbstractType
+{
+    public function buildForm(FormBuilder $builder, array $options)
+    {
+        $builder->add('secret', 'text');
+    }
+}

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

@@ -0,0 +1,44 @@
+{% extends "SymfonyWebConfiguratorBundle::layout.html.twig" %}
+
+{% block title %}Symfony - Configure global Secret{% endblock %}
+
+{% block content %}
+    {% form_theme form "SymfonyWebConfiguratorBundle::form.html.twig" %}
+    {% include "SymfonyWebConfiguratorBundle::steps.html.twig" with { "index": index, "count": count } %}
+
+    <h1>Global Secret</h1>
+    <p>Configure the global secret for your website (the secret is used for the CSRF protection among other things):</p>
+
+    {{ form_errors(form) }}
+    <form action="{{ path('_configurator_step', { 'index': index }) }} " method="POST">
+        <div class="symfony-form-row">
+            {{ form_label(form.secret) }}
+            <div class="symfony-form-field">
+                {{ form_widget(form.secret) }}
+                <a class="symfony-button-grey" href="#" onclick="generateSecret(); return false;">Generate</a>
+                <div class="symfony-form-errors">
+                    {{ form_errors(form.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 generateSecret()
+        {
+            var result = '';
+            for (i=0; i < 32; i++) {
+                result += Math.round(Math.random()*16).toString(16);
+            }
+            document.getElementById('secretstep_secret').value = result;
+        }
+    </script>
+{% endblock %}

+ 77 - 0
Step/SecretStep.php

@@ -0,0 +1,77 @@
+<?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\SecretStepType;
+
+/**
+ * Secret Step.
+ *
+ * @author Fabien Potencier <fabien@symfony.com>
+ */
+class SecretStep implements StepInterface
+{
+    /**
+     * @assert:NotBlank
+     */
+    public $secret;
+
+    public function __construct(array $parameters)
+    {
+        $this->secret = $parameters['secret'];
+
+        if ('ThisTokenIsNotSoSecretChangeIt' == $this->secret) {
+            $this->secret = hash('sha1', uniqid(mt_rand()));
+        }
+    }
+
+    /**
+     * @see StepInterface
+     */
+    public function getFormType()
+    {
+        return new SecretStepType();
+    }
+
+    /**
+     * @see StepInterface
+     */
+    public function checkRequirements()
+    {
+        return array();
+    }
+
+    /**
+     * checkOptionalSettings
+     */
+    public function checkOptionalSettings()
+    {
+        return array();
+    }
+
+    /**
+     * @see StepInterface
+     */
+    public function update(StepInterface $data)
+    {
+        return array('secret' => $data->secret);
+    }
+
+    /**
+     * @see StepInterface
+     */
+    public function getTemplate()
+    {
+        return 'SymfonyWebConfiguratorBundle:Step:secret.html.twig';
+    }
+}