Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2 FOSUser/SonataBundle无效CSRF令牌值_Php_Forms_Symfony_Login_Fosuserbundle - Fatal编程技术网

Php Symfony2 FOSUser/SonataBundle无效CSRF令牌值

Php Symfony2 FOSUser/SonataBundle无效CSRF令牌值,php,forms,symfony,login,fosuserbundle,Php,Forms,Symfony,Login,Fosuserbundle,我想有两个不同的表单(我指的是模板),可以在不同的小枝上登录我的用户。但是我从我的一张表格中得到一个错误。。。这是我一步一步做的: 我在路线上有主登录模板/login此登录有效 为了使第二个表单在/product\u frm中工作,我执行了以下操作: 1) 已为第二个登录控制器创建路由。现在我有两个登录路径: login: path: /login defaults: { _controller: ApplicationSonataUserBundle:SecurityFOS

我想有两个不同的表单(我指的是模板),可以在不同的小枝上登录我的用户。但是我从我的一张表格中得到一个错误。。。这是我一步一步做的:

我在路线上有主登录模板
/login
此登录有效

为了使第二个表单在
/product\u frm
中工作,我执行了以下操作:

1) 已为第二个登录控制器创建路由。现在我有两个登录路径:

login:  
    path: /login
    defaults: { _controller: ApplicationSonataUserBundle:SecurityFOSUser1:login }

loginForm:
    path: /login_frm
    defaults: { _controller: ApplicationSonataUserBundle:LoginFormType:login }
现在这是
/login\u frm
的控制器,它与
/login
控制器相同,只是呈现的模板不同:

<?php
/*
 * This file is part of the Sonata package.
 *
 * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


namespace Application\Sonata\UserBundle\Controller;

use FOS\UserBundle\Controller\SecurityController;
use Sonata\UserBundle\Model\UserInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Sonata\UserBundle\Controller\SecurityFOSUser1Controller as BaseController;


class LoginFormTypeController extends BaseController
{
    public function loginAction()
    {
        $user = $this->container->get('security.context')->getToken()->getUser();

        if ($user instanceof UserInterface) {
            $this->container->get('session')->getFlashBag()->set('sonata_user_error', 'sonata_user_already_authenticated');
            $url = $this->container->get('router')->generate('sonata_user_profile_show');

            return new RedirectResponse($url);
        }

        return parent::loginAction();
    }
    public function renderLogin(array $data)
    {
        $template = sprintf('MpShopBundle:Form:login_form2.html.%s', $this->container->getParameter('fos_user.template.engine'));

        return $this->container->get('templating')->renderResponse($template, $data);
    }

}

因为在标准表单中您有CSRF令牌,而在自定义表单中您没有


您应该在twig中HTML的表单块中添加
{form\u widget(form.\u token)}

它的可能重复项不是重复项,ty:)他有“”,这对于名为
\u csrf\u token
的fosuserinput很好,但是表单名呢?试试我的解决办法。我认为它将生成另一个名称的输入。
{% block fos_user_content %}

    <div class="span9">
        <div class="well">
            {% block sonata_user_login %}
                <div class="panel panel-info">

                <div class="panel-heading">
                    <h2 class="panel-title">{{ 'title_user_authentication'|trans({}, 'SonataUserBundle') }}</h2>
                </div>

                <div class="panel-body">

                    {% block sonata_user_login_error %}
                        {% if error %}
                            <div class="alert alert-danger alert-error">{{ error|trans({}, 'FOSUserBundle') }}</div>
                        {% endif %}
                    {% endblock %}

                    {% block sonata_user_login_form %}
                        <form action="{{ path("fos_user_security_check") }}" method="post" role="form"
                              class="form-horizontal">
                            <input type="hidden" name="_csrf_token" value="{{ csrf_token }}"/>

                            <div class="control-group">
                                <label class="control-label control-label required" for="username"
                                       class="col-sm-4 control-label">{{ 'security.login.username'|trans({}, 'SonataUserBundle') }}</label>

                                <div class="controls">

                                <input type="text" class="form-control" id="username" name="_username" value="{{ last_username }}" required="required"/></div>
                            </div>


                            <div class="form-group control-group">
                                <label class="control-label control-label required" for="password"
                                       class="col-sm-4 control-label">{{ 'security.login.password'|trans({}, 'SonataUserBundle') }}</label>

                                <div class="controls">
                                <input type="password" class="form-control" id="password" name="_password" required="required"/></div>
                            </div>

                            <div class="control-group">
                                <div class="col-sm-offset-4 col-sm-8">
                                    <div class="checkbox control-group">
                                        <label class="checkbox pull-left" for="remember_me">
                                            <input type="checkbox" id="remember_me" name="_remember_me" value="on"/>
                                            {{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class=" control-group pull-left">
                                <div class="">
                                    <a href="{{ path('forgetpass') }}">{{ 'forgotten_password'|trans({}, 'SonataUserBundle') }}</a>
                                </div>
                            </div>

                            <div class="form-actions">
                                <div class="pull-left">
                                    <input type="submit" id="_submit" name="_submit" class="btn btn-primary pull-right"
                                           value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}"/>
                                </div>
                            </div>
                        </form>
                    {% endblock %}
                </div>
            </div>
            {% endblock %}
        </div>
       </div>

{% endblock fos_user_content %}