使用FOSUserBundle登录并注册到同一页面

时间:2016-03-30 14:03:05

标签: fosuserbundle symfony

我正在使用登录并在我的Symfony应用程序中使用fosuserBundle在同一页面注册。登录工作完美但注册不起作用。当我单击按钮注册时,我重定向到login.No在我的数据库中注册。

这是我的login.html.twig:

      {% extends "FOSUserBundle::layout.html.twig" %}

        {% trans_default_domain 'FOSUserBundle' %}

           {% block fos_user_content %}
         {% if error %}
           <div>{{ error.messageKey|trans(error.messageData, 'security') }}
           </div>
       {% endif %}

       <div class="login-container">

          <div class="position-relative">
            <div id="login-box" class="login-box visible widget-box no-border">
              <div class="widget-body">
                <div class="widget-main">
                  <h4 class="header blue lighter bigger">
                    <i class="ace-icon fa fa-coffee green"></i>
                    Please Enter Your Information
                  </h4>

                  <div class="space-6"></div>

                  <form method="post" action="{{ path("fos_user_security_check") }}">
                  <label class="block clearfix">
                        <span class="block input-icon input-icon-right">

                          <input type="text" name="_username" class="form-control" placeholder="{{ 'security.login.username'|trans }}" required="required" />
                          <i class="ace-icon fa fa-user"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">

                          <input type="password" name="_password" class="form-control" value="" placeholder="{{ 'security.login.password'|trans }}" required="required" />
                          <i class="ace-icon fa fa-lock"></i>
                        </span>
                      </label>

                      <div class="space"></div>

                      <div class="clearfix">
                        <label class="inline">
                          <input type="checkbox" class="ace" name="_remember_me" value="{{ 'security.login.remember_me'|trans }}"/>

                          <span class="lbl"> Remember Me</span>
                        </label>

                        <button type="submit" id="_submit" name="_submit"class="width-35 pull-right btn btn-sm btn-primary">
                          <i class="ace-icon fa fa-key"></i>
                          <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />
                            {{ 'security.login.submit'|trans }}   
                        </button>

                      </div>

                      <div class="space-4"></div>

                  </form>

                </div><!-- /.widget-main -->

                <div class="toolbar clearfix">
                  <div>
                    <a href="#" data-target="#signup-box" class="user-signup-link">
                      I want to register
                      <i class="ace-icon fa fa-arrow-right"></i>
                    </a>
                  </div>
                </div>
              </div><!-- /.widget-body -->
            </div><!-- /.login-box -->
            {{ render(controller('FOSUserBundle:Registration:register')) }}
          </div><!-- /.position-relative -->
      </div>

        {% endblock fos_user_content %}

这是我的register.html.twig:

       <div id="signup-box" class="signup-box widget-box no-border">
              <div class="widget-body">
                <div class="widget-main">
                  <h4 class="header green lighter bigger">
                    <i class="ace-icon fa fa-users blue"></i>
                    New User Registration
                  </h4>

                  <div class="space-6"></div>
                  <p> Enter your details to begin: </p>
                  {% block fos_user_content %}
                  {% include "FOSUserBundle:Registration:register_content.html.twig" %}
                                  {% endblock fos_user_content %} 
                </div>

                <div class="toolbar center">
                  <a href="#" data-target="#login-box" class="back-to-login-link">
                    <i class="ace-icon fa fa-arrow-left"></i>
                    Back to login
                  </a>
                </div>
              </div><!-- /.widget-body -->
            </div><!-- /.signup-box -->

这是我的register_content.html.twig:

             {% trans_default_domain 'FOSUserBundle' %}

              {{ form_start(form, {'attr': {'class': 'form-horizontal'} },{'method': 'post', 'action': path('fos_user_registration_register'), 'attr': {'class': 'fos_user_registration_register'}}) }}


                    <fieldset>
                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                        {{ form_widget(form.email,{'attr': {'class': 'form-control'} }) }}

                          <i class="ace-icon fa fa-envelope"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                         {{ form_widget(form.username,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-user"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          {{ form_widget(form.plainPassword.first,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-lock"></i>
                        </span>
                      </label>

                      <label class="block clearfix">
                        <span class="block input-icon input-icon-right">
                          {{ form_widget(form.plainPassword.second,{'attr': {'class': 'form-control'} }) }}
                          <i class="ace-icon fa fa-retweet"></i>
                        </span>
                      </label>

                      <label class="block">
                        <input type="checkbox" class="ace" />
                        <span class="lbl">
                          I accept the
                          <a href="#">User Agreement</a>
                        </span>
                      </label>

                      <div class="space-24"></div>

                      <div class="clearfix">
                        <button type="reset" class="width-30 pull-left btn btn-sm">
                          <i class="ace-icon fa fa-refresh"></i>
                          <span class="bigger-110">Reset</span>
                        </button>

                        <input type="submit" value="{{ 'registration.submit'|trans }}" />
                      </div>
                    </fieldset>
                  {{ form_end(form) }}

1 个答案:

答案 0 :(得分:0)

我通过删除{'attr': {'class': 'form-horizontal'} }中的register_content.html.twig解决了我的问题。