简体   繁体   English

FOSUserBundle(登录/注册)+ AJAX + Symfony2

[英]FOSUserBundle (login / register) + AJAX + Symfony2

I installed FOSUserBundle on my Symfony2 website and I overwrited the login and register pages. 我在Symfony2网站上安装了FOSUserBundle ,并覆盖了登录和注册页面。 It's working very well, but now, I have another issue : 它工作得很好,但是现在,我还有另一个问题:

Making a pop up with an AJAX check for the login and register part, working with the different routes, controllers, etc. 使用AJAX弹出窗口检查登录和注册部分,并使用不同的路由,控制器等。

How to do that the best way ? 最好的方法是怎么做?

My pop up is a simple bootstrap modal of login.html.twig page for FOSUserBundle , here is the code of the modal-body for the login part (I will use the register form for the register part) : 我的弹出窗口是FOSUserBundlelogin.html.twig页面的简单引导模式,这是登录部分的modal-body代码(我将使用注册表格作为注册部分):

<div class="modal-body">
    {% trans_default_domain 'FOSUserBundle' %}

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

            <label for="username">{{ 'security.login.username'|trans }}</label>
            <input type="text" id="username" name="_username" value="" required="required" />

            <label for="password">{{ 'security.login.password'|trans }}</label>
            <input type="password" id="password" name="_password" required="required" />
            <br /><br />
            <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
        </form>
    {% endblock fos_user_content %}
</div>

I already searched on StackOverflow and other websites but didn't find the good answer I was looking for. 我已经在StackOverflow和其他网站上进行了搜索,但是找不到我想要的好答案。

Thank you. 谢谢。

no token when you use AJAX 使用AJAX时没有令牌

user=$('#username').val();
pass=$('password').val();
$.ajax(
     {
     type: "POST",
     url: "{{ path ('your-rout')}}",
     data: {'user': user,'pass':pass},
      beforeSend: function() {
       },
      success: function(json) {}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM