0

I am installing the FOSUserBundle which i have downloaded from Knpbundle.

I have configured it properly as the instruction given.

I have created a route so my 'app/config/routing.yml' is as bellow.

fos_user_security:
   resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
   resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
   prefix: /profile

fos_user_register:
  resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
  prefix: /register

fos_user_resetting:
  resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
  prefix: /resetting

fos_user_change_password:
  resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
  prefix: /profile
acme_user:
  resource: "@AcmeUserBundle/Resources/config/routing.yml"
  prefix: /

And my routing.yml file is as bellow.

AcmeUser_Bundle:
  pattern: /admin
  defaults: { _controller: AcmeUserBundle:User:index}

As soon as I pass /admin in my url it will called the index file view which I have created.the index file looking like this.

 <body>

<section id="login_form">
  <div class="login_form_head">Administration</div>
<form  id="admin_login_form" class="formee" method="post" action="{{
 path('fos_user_security_check') }}" enctype="multipart/form-data">

    <div class="login_form_display">
    <div class="login_row"><input type="text" name="_username"
 class="validate[required,custom[username]]" id="username" 
 placeholder="Username" /></div>
           <div class="clear"></div>
<div class="login_row"><input type="password"  class="validate[required,custom[passwordLogin]]"
   name="_password" id="password" placeholder="Password" /></div>
        <div class="clear"></div>
    </div>

    <!--Form footer begin -->
    <section class="login_footer">
            <div class="textcenter"><input type="submit" value="Login" /></div>
        <div class="clear"></div>
    </section>
    <!--Form footer end -->

    </form>                 
</section><!-- End of #container -->
 <div>
{% if is_granted("IS_AUTHENTICATED_REMEMBERED") %}
 {{ 'layout.logged_in_as'|trans({'%username%': app.user.username}, 'FOSUserBundle') }} |
            <a href="{{ path('fos_user_security_logout') }}">
                {{ 'layout.logout'|trans({}, 'FOSUserBundle') }}
            </a>
        {% else %}

            <a href="{{ path('fos_user_security_login') }}">{{ 'login'|trans({}, 'FOSUserBundle') }}</a>
        {% endif %}
    </div>

    {% for type, messages in app.session.flashbag.all() %}
        {% for key, message in messages %}
            <div class="flash-{{ type }}">
                {{ message|trans({}, 'FOSUserBundle') }}
            </div>
        {% endfor %}
    {% endfor %}

    <div>
        {% block fos_user_content %}




        {% endblock fos_user_content %}
    </div>

</body>

It shows the csrfToken error. So pls can any one help me understand.

j0k
  • 22,600
  • 28
  • 79
  • 90
Viraj.S
  • 305
  • 1
  • 8
  • 18
  • I guess there is something wrong in your Controller. Take a look at this http://stackoverflow.com/questions/10442922/symfony2-csrf-invalid – Shrujan Shetty Mar 07 '13 at 06:39
  • u can see the controoler which come with this bundle it is not calling the checkAction() still it is working. i do not know how to? – Viraj.S Mar 07 '13 at 06:43
  • are you sonata admin bundle along with FOS User bundle? – Shrujan Shetty Mar 07 '13 at 06:53
  • no only FOS USer Bundle – Viraj.S Mar 07 '13 at 06:54
  • if u have any working example of simple login from starting confing.yml to the controller to the dashboard then pls give me so that it makes me sense. as i m new to symfony so pls help me if possible – Viraj.S Mar 07 '13 at 07:18

1 Answers1

0

You missed this <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" /> in your log in form.
CSRF TOKEN are generated at every request and should be unique. In that way, you (or, in this case, FOSUserBundle for you) can prevent CSRF ATTACKS.

FOSUserBundle generate it for you but, as he expect to have it posted along the form, you have to include it

A little note

I'm also not sure what you're trying to do here. If you want to customize look and feel of FOSUserBundle log in form, you should override it in the proper way
If you find a more suitable way, please take a look at this answer

Community
  • 1
  • 1
DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • yes i want to override it into mylogin form and want to know how it work with my custom login form. and want to set session for it too. – Viraj.S Mar 07 '13 at 08:28