Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User discriminator based on class instead of name? #112

Open
clytemnestra opened this issue Apr 19, 2016 · 0 comments
Open

User discriminator based on class instead of name? #112

clytemnestra opened this issue Apr 19, 2016 · 0 comments
Labels

Comments

@clytemnestra
Copy link

I want to provide different login/register pages/forms for my users, but the users are the same class. I don't want to populate the database with additional tables.

pugx_multi_user:
  users:
    normal:
        entity: 
          class: AppBundle\Entity\SfGuardUser
        registration:
          form:
            type: Application\FOS\UserBundle\Form\RegistrationType
          template: AcmeUserBundle:Registration:1.form.html.twig
    admins:
        entity: 
          class: AppBundle\Entity\SfGuardUser
        registration:
          form:
            type: Application\FOS\UserBundle\Form\RegistrationType
          template: ApplicationFOSUserBundle:Registration:2.html.twig
class RegistrationController extends Controller
{
    /**
     * @Route("/asd1", name="login1")
     */
    public function registerUserAction()
    {
        return $this->container
            ->get('pugx_multi_user.registration_manager')
            ->register('AppBundle\Entity\SfGuardUser');
    }

    /**
     * @Route("/asd2", name="login2")
     */
    public function registerAdminAction()
    {
        return $this->container
            ->get('pugx_multi_user.registration_manager')
            ->register('AppBundle\Entity\SfGuardUser');
    }
}

This configuration doesn't work unfortunately, mainly because UserDiscriminator takes values by class instead of user type names. For instance, to get the template, the discriminator does this

    /**
     * 
     * @return string
     */
    public function getTemplate($name)
    {
        return $this->conf[$this->getClass()][$name]['template'];
    }

Which will return it by AppBundle\Entity\SfGuardUser instead of normal or admins

Is there a way to have a single class for multiple types of users?

@garak garak added the question label Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants