Question

I'm absolutely new of Symfony, and I'm trying to implement a registration form that works only with invitation but that can redirect two different forms for two different roles.

In practice if I send an invitation for an USER_TYPE1 role the client can only register like USER_TYPE1, if I send an invitation for an USER_TYPE2 the client can only register like USER_TYPE2 (and, of course, assigns the corrispondent role).

Is it possible?

thank you in advance for your help

UPDATE:

I want two different form because one user will be allowed to update file, but will also have to set his position and other important settings. The second user will only allow to download the files uploaded by the first kind of user, and his profile needs completely different information.

Was it helpful?

Solution

I do not have enough reputation to ask for details, but one thing that is not clear in your question is: why do you need 2 different forms? In your question, you mention 2 different roles, but why do you need 2 different forms? If you really need 2 different forms, then you should first: - create a new form type - create a new view (twig)

Like Boris suggested, I would keep some kind of token for every invitation sent, and associate an email address, and a role to it. Then modify your registration route so you can pass a token in there, like this:

register:
    pattern:   /signup/{token}
    defaults:  { _controller: MyBundle:Registration:signup }

In the registration action of your controller, you created the correct form type and display the appropriate twig, depending on the ROLE associated to the token you just got. And when handling a POST, you check the Token again to see if it matches the email address, and assign the proper ROLE when creating the User.

public function signupAction($token) {
    // 1. Get the Token entity matching the $token variable
    // 2. Create the correct form type
    // 3. Display the correct twig for GET, assign correct ROLE to new User for POST
}

But you can't use FOSUserBundle as-is. You will have to overwrite the registration process. You can read the FOSUserBundle documentation about that.

What's certain is that, for every invitation you send, you should keep a token with a matching email address and ROLE (the role you want to give to that person).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top