Sonata Admin + User Bundle + FOS UserBundle : override login form

1,319 views
Skip to first unread message

Sylvain Zyssman

unread,
Sep 17, 2015, 4:16:28 AM9/17/15
to sonata-users
Hi,

I'm using Sonata admin, Sonata user, and FOS Bundle.
I manage to override the UserAdmin entity to show the fields I need when showing / editing a user, but I'd need to override login form.

Basically, I need the user to login with a username, and a combination of both a password and a PIN code.
I followed this tutorial http://symfony.com/doc/current/bundles/FOSUserBundle/overriding_forms.html and tried with the registration form as in the example, but no matter what I do, I still have the same original fields.

My Kernel file uses this :
new FOS\UserBundle\FOSUserBundle(),
new Application\FOS\UserBundle\ApplicationFOSUserBundle(),
new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),
new UserBundle\UserBundle(), //my custom bundle where I define my entity, my UserAdmin...

My custom form, which does not implement getParent() to use my own fields, as specified in the doc:

<?php

namespace UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RegistrationType extends AbstractType
{
   
public function buildForm(FormBuilderInterface $builder, array $options)
   
{
        $builder
->add('pinCode');
   
}

   
public function getName()
   
{
       
return 'app_user_registration';
   
}
}



The service is declared
<service id="coupons_user.registration.form.type" class="UserBundle\Form\RegistrationFormType">
       
<tag name="form.type" alias="app_user_registration" />
       
<argument>%fos_user.model.user.class%</argument>
</service>


The form is declared in FOS config :

registration:
        form
:
            type
: app_user_registration


But whatever I try, no changes... I know I'm doing something wrong.. but where ?
Will it be the same process for the login form ? How can I override this form to display my fields ? And then, what would be the best way to override controllers to have it check that the triplet username/password/PIN is correct ?

Thanks in advance !!

Sylvain Zyssman

unread,
Oct 13, 2015, 12:40:37 PM10/13/15
to sonata-users
No one ever faced the need to customize a form that way ? :'(

Oscar Chan

unread,
Oct 26, 2015, 7:59:43 AM10/26/15
to sonata-users
Just want to say, I was trying to use these 3 bundles together but really complex to setup. Wish there will be a good documentation, for these 3 bundles, together.

Cassiano Tartari

unread,
Oct 26, 2015, 8:13:38 AM10/26/15
to sonata-users
Please check if your SonataUserBundle is overriding FOSUserBundle, if you put in AppKernel.php this:


new Sonata\UserBundle\SonataUserBundle('FOSUserBundle'),

You are doing it, so this is probably the reason for your settings aren't working. You should take a look in sonata-project/user-bundle/Resources/views/Security/login.html.twig

The best option is extend SonataUserBundle (php app/console sonata:easy-extends:generate SonataUserBundle -d src) and play with login.html.twig. About change login check I can't remember right now but probably is a FOSUserBundle issue, read the docs and check SonataUserBundle code. Maybe is related to forms handlers https://sonata-project.org/bundles/user/master/doc/reference/advanced_configuration.html

Att.,
Cassiano Tartari

2015-10-26 9:59 GMT-02:00 Oscar Chan <oscarch...@gmail.com>:
Just want to say, I was trying to use these 3 bundles together but really complex to setup. Wish there will be a good documentation, for these 3 bundles, together.

--
You received this message because you are subscribed to the Google Groups "sonata-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonata-users...@googlegroups.com.
To post to this group, send email to sonata...@googlegroups.com.
Visit this group at http://groups.google.com/group/sonata-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages