pugx / pugxmultiuserbundle Goto Github PK
View Code? Open in Web Editor NEWThis project forked from netmeansnet/nmnmultiuserbundle
An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
This project forked from netmeansnet/nmnmultiuserbundle
An extension for FOSUserBundle to handle users of different types. Compatible with Doctrine ORM.
Hi,
First of all, great job with the bundle. It really helped!
In our project, we need custom profile forms for each type of user.
The question is: Would it be possible to pass custom variables when rendering custom registration templates?
We managed a simple solution, but definetly not a persistent one, as we modified vendor's code.
Here it is:
/*
* Renders user type 1 profile form
*/
public function profileAction() {
$data = array(
'variable1' => $variable1,
'variable2' => $variable2
);
return $this->container
->get('pugx_multi_user.registration_manager')
->register('XXX\XXX\Entity\UserType1',$data);
}
/**
*
* @param string $class
* @param array $vars
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function register($class,$vars = null)
{
$this->userDiscriminator->setClass($class);
$this->controller->setContainer($this->container);
$result = $this->controller->registerAction($this->container->get('request'));
if ($result instanceof RedirectResponse) {
return $result;
}
$template = $this->userDiscriminator->getTemplate('registration');
if (is_null($template)) {
$engine = $this->container->getParameter('fos_user.template.engine');
$template = 'FOSUserBundle:Registration:register.html.'.$engine;
}
$form = $this->formFactory->createForm();
$variables = array (
'form' => $form->createView()
);
if (!empty($vars) && is_array($vars)) {
$variables = array_merge($variables,$vars);
}
return $this->container->get('templating')->renderResponse($template, $variables);
}
Thanks in advance!
is possible to have the user auto-login after registration ? with no confirm email of course.
I've found these but are about FOS
http://stackoverflow.com/questions/9550079/how-to-programmatically-login-authenticate-a-user
http://stackoverflow.com/questions/5886713/automatic-post-registration-user-authentication
Is that available to add easy a profil template by usertype?
As controllers look bit diffrent than in FOSUserBundle, how can I put some custom logic after registration process? For example I want to send a e-mail to registered user. Where should I put this and how can I fetch registered user entity before he's logged in.
Hello everyone,
I need to override the default FOS\UserBundle\Controller\RegistrationController for disabling automatic connection after registration. So I created my RegistrationController in my bundle, just like how FOSUserBundle documentation recommends.
But because of the following lines in PUGX's services.yml:
pugx_multi_user.registration_controller:
class: FOS\UserBundle\Controller\RegistrationController
my overridden RegistrationController is not taken in count. Do you know if it is possible to override PUGX's services.yml file, in order to do something like:
pugx_multi_user.registration_controller:
class: Acme\UserBundle\Controller\RegistrationController
Regards,
When I execute:
sudo php composer.phar update pugx/multi-user-bundle
I get this error:
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for pugx/multi-user-bundle dev-master -> satisfiable by pugx/multi-user-bundle dev-master.
- pugx/multi-user-bundle dev-master requires friendsofsymfony/user-bundle dev-master -> no matching package found.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see for more details.
My composer.json:
"require": {
//...//
"friendsofsymfony/user-bundle": "*",
"pugx/multi-user-bundle": "dev-master"
},
Any solution?
I have a problem when I make a registration of a user when I use FosUserBundle with Sylius and PUGXMultiUserBundle to make more than one type of user(Role) :
User.php :
namespace Sylius\Bundle\CoreBundle\Model;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\UserBundle\Model\User as BaseUser;
use Sylius\Bundle\AddressingBundle\Model\AddressInterface;
/**
* @ORM\Entity(repositoryClass="App\myBundle\Entity\UserRepository")
* @ORM\Table(name="sylius_user")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="user_type", type="string")
* @ORM\DiscriminatorMap({"student" = "StudentUser", "partner" = "PartnerUser"})
abstract class User extends BaseUser implements UserInterface
{
protected $firstName;
protected $lastName;
protected $createdAt;
protected $updatedAt;
protected $currency;
protected $orders;
protected $billingAddress;
protected $shippingAddress;
protected $addresses;
StudentUser.php:
use Doctrine\ORM\Mapping as ORM;
use PUGX\MultiUserBundle\Validator\Constraints\UniqueEntity;
use Sylius\Bundle\CoreBundle\Model\User;
/**
* @ORM\Entity(repositoryClass="App\MyBundle\Entity\UserRepository")
* @ORM\Table(name="sylius_user_staff")
* @UniqueEntity(fields = "username", targetClass = "Sylius\Bundle\CoreBundle\Model\User", message="fos_user.username.already_used")
* @UniqueEntity(fields = "email", targetClass = "Sylius\Bundle\CoreBundle\Model\User", message="fos_user.email.already_used")
*/
class StudentUser extends User
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
So when I would to register a new student, I get this error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.username_canonical' in 'where clause'
That means directly that they not find the username_canonical in User.php class (Sylius\Bundle\CoreBundle\Model) and he refuse to extend it from User.php calss of FosUserBundle?Someone have a solution please?
Hi everyone,
When I try to impersonating a user, sometime I experiencing the following error :
Impossible to set the class discriminator, because the class "Proxies\__CG__\Project\FooBundle\Entity\User\Staff" is not present in the entities list
In the discriminate function of PUGX\MultiUserBundle\Listener\AuthenticationListener class, I have try this solution to avoid doctrine proxies :
protected function discriminate($user)
{
$className = \Doctrine\Common\Util\ClassUtils::getClass($user);
$this->userDiscriminator->setClass($className, true);
}
But this seem doesn't works, I'm automatically redirected to login page.
Any better idea ?
Hi,
I recently started using the PUGXMultiUserBundle, but there doesn't seem to be the possibility to pass additional parameters to the constructor of RegistrationFormType.
The reason to pass these parameters is because the form contains a 'country' dropdown field which needs to be localized. The countries come from a database, while the translations come from the translation files.
My RegistrationFormType looks like this:
class RegistrationFormType extends BaseType { private $doctrine; private $translator; public function __construct($class, RegistryInterface $doctrine, $translator) { parent::__construct($class); $this->doctrine = $doctrine; $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) { $countries = $repository = $this->doctrine->getRepository('AcmeBaseBundle:Country')->findAll(); $dropdown_countries = array(); foreach($countries as $country) { $dropdown_countries[$country->getCodeISOa2()] = $this->translator->trans('country_'.$country->getCodeISOa2()); } $builder->add('country', 'choice', array( 'attr' => array('class' => 'countriesDropdown'), 'label' => 'registration_label_country', 'choices' => $dropdown_countries)); }
config.yml:
pugx_multi_user: users: user_create_my_book: entity: class: Acme\Bundle\UserBundle\Entity\MyCustomUser registration: form: type: Acme\Bundle\UserBundle\Form\Type\RegistrationFormType arguments: [%fos_user.model.user.class%, @doctrine, @translator ] tags: - { name: form.type, alias: acme_user_registration_form } name: acme_custom_user_registration validation_groups: [Registration, Default] template: FOSUserBundle:Registration:register.html.twig
Acme/Bundle/UserBundle/Resources/config/services.xml :
<service id="acme_user.registration.form.type" class="Acme\Bundle\UserBundle\Form\Type\RegistrationFormType"> <tag name="form.type" alias="acme_custom_user_registration" /> <argument>%fos_user.model.user.class%</argument> <argument type="service" id="doctrine" /> <argument type="service" id="translator"></argument> </service>
I get this error:
InvalidConfigurationException: Unrecognized options "arguments, tags"
If I leave out this part from config.yml:
arguments: [%fos_user.model.user.class%, @doctrine, @translator ] tags: - { name: form.type, alias: acme_user_registration_form }
I get this error:
Catchable Fatal Error: Argument 2 passed to Acme\Bundle\UserBundle\Form\Type\RegistrationFormType::__construct() must implement interface Symfony\Bridge\Doctrine\RegistryInterface, none given, called in vendor/pugx/multi-user-bundle/PUGX/MultiUserBundle/Model/UserDiscriminator.php on line 155 and defined in src/Acme/Bundle/UserBundle/Form/Type/RegistrationFormType.php line 14
Could you please help me out with this?
Thanks alot!
Kr,
Michael
InvalidArgumentException: The service definition "fos_user.registration.form.factory" does not exist.
Hi,
I have two users A and B.
They are defined in the config.yml under the pugx_multi_user: users: section.
But the remember_me functionality only works for the first user defined.
Does someone have a clue how to fix it, or how to implement a workaround?
Thanks,
David
Hi all!
There are two different types of users (UserOne and UserTwo). And both of them have users with the same username "testuser".
in parameters.yml
parameters:
pugx_user_discriminator_parameters:
classes:
user_one:
entity: Acme\DemoBundle\Entity\UserOne
...
user_two:
entity: Acme\DemoBundle\Entity\UserTwo
...
PUGXMultiUserBundle/UserDiscriminator sets an array with these two entities:
["Acme\DemoBundle\Entity\UserOne", "Acme\DemoBundle\Entity\UserTwo"]
Both types have different login pages with different routes:
user_one_login:
pattern: /user_one/login
defaults: { _controller: AcmeDemoBundle:UserOneSecurity:login }
user_one_check:
pattern: /user_one/login_check
defaults: { _controller: AcmeDemoBundle:UserOneSecurity:check }
user_two_login:
pattern: /user_two/login
defaults: { _controller: AcmeDemoBundle:UserTwoSecurity:login }
user_two_check:
pattern: /user_two/login_check
defaults: { _controller: AcmeDemoBundle:UserTwoSecurity:check }
Controllers are extended from FOS\UserBundle\Controller\SecurityController and don't have checkAction method defined - parent method used.
Issue:
When UserTwo with username "testuser" logins, PUGXMultiUserBundle/UserManager returns UserOne with the same username, because it has been found in the first entity from UserDiscriminators::$entities.
Question:
How this issue could be solved?
Thank you
hi,
Thank you for the great work.
I need to disable the default functionality.
I know that this is about FOSUSerBundle but I'm using PUGXMultiUserBundle which override the default comtroler
public function registerAction()
{
return $this->container
->get('pugx_multi_user.registration_manager')
->register('Acme\UserBundle\Entity\UserOne');
}
Any response will be appreciated.
Hi there,
I'm new to Symfony2 and Git. I dont know hot to put under light my code. If you would edit it, feel free to do.
I met this error after having configured my bundle to allow a specific hierarchy of entities:
Unrecognized options "users" under "pugx_user"
It seems that this file is in cause:
//Provocation/UserBundle/Resources/config/config.yml
pugx_multi_user:
users:
candidat:
entity:
class: Provocation\UserBundle\Entity\Candidat
# factory:
registration:
form:
type: Provocation\UserBundle\Form\Type\CandidatRegistrationFormType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: ProvocationUserBundle:Registration:user_one.form.html.twig
profile:
form:
type: Provocation\UserBundle\Form\Type\ProfileUserOneFormType
name: fos_user_profile_form
validation_groups: [Profile, Default]
support:
entity:
class: Provocation\UserBundle\Entity\Support
registration:
form:
type: Provocation\UserBundle\Form\Type\SupportRegistrationFormType
template: ProvocationUserBundle:Registration:user_two.form.html.twig
profile:
form:
type: Provocation\UserBundle\Form\Type\ProfileUserTwoFormType
It is a real problem since I can not do anything from now on. Everything has been made as explained if you documentation (maybe not totaly since i've this error). So controllers, forms and entities are made.
I have absolutly no idea about where it comes from.
I have checked if the indent were OK in my config.yml, but seems like nothing is wrong in it.
There is how my composer.json is configured (I use Sf2.1.8):
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.5-dev",
"doctrine/doctrine-bundle": "1.1.*",
"twig/extensions": "1.0.*@dev",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*@dev",
"friendsofsymfony/user-bundle": "*",
"pugx/multi-user-bundle": "1.4.x-dev"
},
Hi,
I have the following entities based on the bundle:
use FOS\UserBundle\Model\User as BaseUser;
/**
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Table(name="core_user")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"partner_contact" = "PartnerContact", "member" = "Member"})
*/
abstract class User extends BaseUser
{}
That's my base entity. Then, I have two sub-childs entities, that have the following mappings.
/**
* @ORM\Table(name="core_member")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @ORM\Entity(repositoryClass="Justmoov\BackBundle\Repository\MemberRepository")
* @UniqueEntity(fields = "username", targetClass = "Justmoov\BackBundle\Entity\User", message="fos_user.username.already_used")
* @UniqueEntity(fields = "email", targetClass = "Justmoov\BackBundle\Entity\User", message="fos_user.email.already_used")
* @ExclusionPolicy("all")
*/
class Member extends User
{}
And the same for my other sub-class:
/**
* * Justmoov\BackBundle\Entity\PartnerContact
* @ORM\Table(name="core_partner_contact")
* @ORM\Entity
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity(fields = "username", targetClass = "Justmoov\BackBundle\Entity\User", message="fos_user.username.already_used")
* @UniqueEntity(fields = "email", targetClass = "Justmoov\BackBundle\Entity\User", message="fos_user.email.already_used")
* @ExclusionPolicy("all")
*/
class PartnerContact extends User
{}
So, as you can see, both sub-classes have the @UniqueEntity
constraint validator, and therefore, I should not be able to register a PartnerContact
with an email if there is some Member
with the same username / email.
I have a member with the email [email protected]. When trying to register e new member with that email, I get the correct error message in the form. Nevertheless, when trying to register a partnerContact with that email, the $forn->isValid()
apparently returns true, and therefore, it tries to insert the entity in the database, and there is where i get the error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '[email protected]' for key 'UNIQ_BF76157C92FC23A8'
For registering, I'm using the controllers as shown in the documentation.
For Members,
public function registerAction()
{
return $this->get('pugx_multi_user.registration_manager')
->register('Justmoov\BackBundle\Entity\Member');
}
And for PartnerContact:
public function registerAction()
{
return $this->get('pugx_multi_user.registration_manager')
->register('Justmoov\BackBundle\Entity\PartnerContact');
}
Is there something that I'm missing or is this just a bug? Or really, the validator is only for entities of the same sub-class?
Thanks!
I'm trying to install PUGXMultiUserBundle, but I get the following message when i do a composer.phar update
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: friendsofsymfony/user-bundle[2.0.x-dev, 1.3.x-dev].
- Can only install one of: friendsofsymfony/user-bundle[2.0.x-dev, 1.3.x-dev].
- pugx/multi-user-bundle dev-master requires friendsofsymfony/user-bundle 2.0.x-dev@dev -> satisfiable by friendsofsymfony/user-bundle[2.0.x-dev].
- Installation request for pugx/multi-user-bundle dev-master -> satisfiable by pugx/multi-user-bundle[dev-master].
- Installation request for friendsofsymfony/user-bundle 1.3.x-dev -> satisfiable by friendsofsymfony/user-bundle[1.3.x-dev].
composer.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"symfony/process": "2.3.*@dev",
...
"friendsofsymfony/user-bundle": "2.0.@dev",
"pugx/multi-user-bundle": "dev-master",
...
Hey guys,
First of all, great work for the bundle (even if I had hard time to make it works ^^).
I have a small "problem", and I need some help to go through.
I have the following user inheritance :
Candidat and Pro inherit of User.
I want to override the handler for Pro registration. How can I do that without breaking the way PUGX works ?
Thank you very much.
Gregoriz
I was wondering, is it possible to have multiple login forms?
For example, if I have 2 users, member and admin, /login/member would display a form to login a member and /login/admin would display a form to login an admin.
Plus, I was wondering if it would be possible to have a user that is both a member and an admin using the same email address?
In my application, member and admins have different attribute fields (It's a social networking application and member have friends for example)
How is it possible to manually create the user with the fos user manager?
When I create a new user I dont know how to make this user a userOne or userTwo.
I'm on branch 1.2.
Without this Bundle I would use the following code:
$userManager = $this->get('fos_user.user_manager');
$user = $userManager->createUser();
$user->setSomeData();
...
Only the first user type can be registered. When i change the config.yml the user, it will be changed to the other user.
pugx_multi_user:
users:
user_worker:
entity:
class: Mas\UserBundle\Entity\UserWorker
registration:
form:
type: Mas\UserBundle\Form\Type\RegistrationUserWorkerFormType
template: MasUserBundle:Registration:user_worker.form.html.twig
profile:
form:
type: Mas\UserBundle\Form\Type\ProfileUserWorkerFormType
user_customer:
entity:
class: Mas\UserBundle\Entity\UserCustomer
registration:
form:
type: Mas\UserBundle\Form\Type\RegistrationUserCustomerFormType
template: MasUserBundle:Registration:user_customer.form.html.twig
profile:
form:
type: Mas\UserBundle\Form\Type\ProfileUserCustomerFormType
A other guy have the same problem:
http://stackoverflow.com/questions/17045253/symfony2-pugxmultiuserbundle-i-can-register-only-one-type-of-user
Hello,
I am using PUGXMultiUserBundle and it is awesome. Good work !
I wanted to know if it is possible to use the firewall to authorize or not UserOne and not UserTwo for instance for the route /userone/profile ?
Regards,
Ben
I was just wondering if you guys know if it is possible to use SonataUserBundle
working with PUGXMultiUserBundle
?
I have been trying for quite a long time now, but I really struggle.... I just wana know if it is better to use SonataAdminBundle
and then customize it so that we can create classOne
users and classTwo users
or if it is indeed possible to use SonataUserBundle
directly?
I was thinking that because you created this bundle, you might have an idea of how I could do the backend :-)
Many many thanks
I'm trying to add the registration with invitation code described in the FOSUserBundle documentation but the invitation code dos not get to the part where the user is created, the registration form keeps telling me it cannot be null.
Is it possible to apply the "cookbook" directly to PUGXMultiUserBundle?
Has anyone tried to do it?
Thanks and regards.
Hi,
I've got 2 user entities in my UserBundle and 2 groups. Each group has an attribute 'admin' (which is a one-to-many relationship) and an attribute 'users' (which is a many-to-many relationship).
In my group forms, i'd like to be able to choose an admin and several users.
My problem is when I do this, the inverse side of my relationships (users and admin) aren't update.
So I tried to pass the option 'by_reference => false' to my form fields. But now I have the following error :
"Entities passed to the choice field must be managed. Maybe persist them in the entity manager?"
So what I'd like to do know is pass the user manager to the form field, but the option 'em' requires a string as a parameter, and I don't know where to find the user manager name.
Can someone explain, how can I import my config file from my Bundle to the root settings file (app/config)
The installation expect this:
Acme/UserBundle/Resources/config/config.yml
Using Symfony 2.4.1 and adding these lines in the composer.json :
"friendsofsymfony/user-bundle": "2.0.@dev",
"pugx/multi-user-bundle": "3.0.@dev",
"doctrine/doctrine-bundle": "1.2.*@dev"
Always return :
Problem 1
- Installation request for pugx/multi-user-bundle 3.0.*@dev -> satisfiable by pugx/multi-user-bundle[3.0.x-dev].
- pugx/multi-user-bundle 3.0.x-dev requires doctrine/doctrine-bundle 1.2.x-dev -> no matching package found.
Potential causes:
Seems to be blocked by doctrine-bundle... Any idea ?
Hi @leopro,
Thanks for this amazing bundle, could you give us any tips on the backend implementation, ie...
Do you have any tips on what bundles to choose to implement the backend with PUGXMultiUserBundle
. At the moment, I am using SonataAdminBundle
with SonataUseBundle
and it seems to work reasonably well.ย
Because you are the creator of this bundle, I thought I would just ask you what you think is preferable to use along PUGXMultiUserBundle
for user management on the backend side?
Do you create a particular user type for your admin people?
If we have a website with type 1 : buyers
and type 2 : sellers
, and we use PUGXMultiUserBundle with 2 types: buyers and sellers. Would you create a type 3 : admins
, or would you register any admins as either type 1 : buyers
or type 2 : sellers
?
Many thanks @leopro,
Very much appreciated.
Sydney-o9
Hi,
i have an error updating composer (usualy it's works fine):
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- pugx/multi-user-bundle dev-master requires doctrine/doctrine-bundle 1.2.x-dev -> no matching package found.
- pugx/multi-user-bundle 3.0.x-dev requires doctrine/doctrine-bundle 1.2.x-dev -> no matching package found.
- remove pugx/multi-user-bundle 3.0.x-dev|keep pugx/multi-user-bundle dev-master
- Installation request for pugx/multi-user-bundle 3.0.*@dev -> satisfiable by pugx/multi-user-bundle[3.0.x-dev].
So, my require :
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.3.",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.",
"pugx/multi-user-bundle": "3.0.*@dev"...
I'm Trying to change with :
"doctrine/doctrine-bundle": "1.2.*",
"doctrine/doctrine-bundle": "1.2.*@dev"
And then i have new error
Problem 1
- Installation request for symfony/framework-standard-edition 2.3.x-dev -> satisfiable by symfony/framework-standard-edition[2.3.x-dev].
- Conclusion: remove symfony/symfony v2.3.7
- symfony/framework-standard-edition 2.3.x-dev requires pugx/multi-user-bundle 3.0.*@dev -> satisfiable by pugx/multi-user-bundle[3.0.x-dev].
I'm trying with SF 2.3.6 , SF 2.3.7 and SF 2.3.9
PHP from 5.4.6 to 5.5.8
Same error all time.
Can you help me ?
Thanks
Alex
I use my RegitrationForm for 2 cases Registration and Edition
so i have a closure in my validation_groups of my RegistrationForm like this :
$resolver->setDefaults(array(
'validation_groups' => function(Form\FormInterface $form) {
$user = $form->getData();
if ($user->getId()) {
return array('Edit');
} else {
return array('Registration');
}
}
));
The validation_groups of my configuration override my validation_groups of my RegistrationFormType and if i delete the validation_groups of my config.yml the default value are set
The PUGXFormFactory override the FormType validation_groups in createForm method like this :
public function createForm()
{
$type = $this->userDiscriminator->getFormType($this->type);
$name = $this->userDiscriminator->getFormName($this->type);
$validationGroups = $this->userDiscriminator->getFormValidationGroups($this->type);
if (array_key_exists($name, $this->forms)) {
return $this->forms[$name];
}
$form = $this->formFactory->createNamed(
$name,
$type,
null,
array('validation_groups' => $validationGroups));
$this->forms[$name] = $form;
return $form;
}
why override the validation_groups in FormFactory? why not keep the validation that already exist in Formtype?
Hi,
I'm trying to set a user role on registration but since I installed the MultiUserBundle it doesn't work anymore.
public function onRegistrationSuccess(FormEvent $event)
{
$user = $event->getForm()->getData();
$userManager = $this->container->get('pugx_user_manager');
$role = array('ROLE_USER');
$user->setRoles($role); //doesn't work
$user->setFirstname('Hans'); //works great
$userManager->updateUser($user, true);
}
Thanks,
David
Hi,
Thank you for this super bundle.
I hope to install it because it is a bundle that I hoped for a long time.
However, I can not install it.
I followed the steps but I think I'm doing something wrong on the form overriding.
Do you know what I have to override exactly?
Currently I have added "RegistrationUserOneFormType", "RegistrationUserTwoFormType", "ProfileUserOneFormType", "ProfileUserTwoFormType" en les copiant de FOSUserBundle.
For instance,
class RegistrationUserOneFormType extends AbstractType
{
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('plainPassword', 'repeated', array(
'type' => 'password',
'options' => array('translation_domain' => 'FOSUserBundle'),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'intention' => 'registration',
));
}
public function getName()
{
return 'fos_user_registration_user_one';
}
}
When i go to /register/userone, I have the following issue
Fatal error: Cannot instantiate abstract class IH\UserBundle\Entity\User in /Symfony/vendor/symfony/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php ...
Indeend, in the PUGXMultiUserBundle bundle, the User class is abstract but the 2 classes UserOne and UserTwo aren't.
I don't know where I need to instantiate my classes? Should I overload FormHandler, and if yes, how?
Sorry for my English,
Regards,
Benjamin
In the the logs i become the follow message:
DEPRECATION - FOS\UserBundle\Entity\User is deprecated. Extend FOS\UserBundle\Model\User directly. -
Called from User::__construct() at line 19
Called from UserFactory::build() at line 126
Called from UserDiscriminator::createUser() at line 57
Called from UserManager::createUser() at line 43
Called from RegistrationController::registerAction() at line 63
Called from RegistrationManager::register() at line 11
Called from RegistrationUserCustomerController::registerAction()
Called from call_user_func_array() at line 1001
Below is my composer.json
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2",
"twig/extensions": "~1.0",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~2.3",
"sensio/framework-extra-bundle": "~3.0",
"sensio/generator-bundle": "~2.3",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "~2.0@dev",
"jms/security-extra-bundle": "dev-master",
"pugx/multi-user-bundle": "3.0.*@dev"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
But when I tried to install with the command
php composer.phar update pugx/multi-user-bundle
error occurred below
Problem 1
- Installation request for pugx/multi-user-bundle 3.0.*@dev -> satisfiable by pugx/multi-user-bundle[3.0.x-dev].
- pugx/multi-user-bundle 3.0.x-dev requires doctrine/doctrine-bundle 1.3.* -> no matching package found.
Problem 2
- pugx/multi-user-bundle 3.0.x-dev requires doctrine/doctrine-bundle 1.3.* -> no matching package found.
- symfony/framework-standard-edition 2.4.x-dev requires pugx/multi-user-bundle 3.0.*@dev -> satisfiable by pugx/multi-user-bundle[3.0.x-dev].
- Installation request for symfony/framework-standard-edition 2.4.x-dev -> satisfiable by symfony/framework-standard-edition[2.4.x-dev].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
FatalErrorException: Error: Call to undefined method dwm\banqBundle\Entity\Client::setEnabled() in C:\wamp\www\pfe1\vendor\friendsofsymfony\user-bundle\FOS\UserBundle\Controller\RegistrationController.php line 44
Hello ALL,
i'm trying to install multi-user-bundle, but i have this error :
php composer.phar update pugx/multi-user-bundle
Package "pugx/multi-user-bundle" listed for update is not installed. Ignoring.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Can only install one of: symfony/symfony[v2.1.9, 2.1.x-dev].
- Can only install one of: symfony/symfony[v2.1.9, 2.1.x-dev].
- Installation request for symfony/symfony v2.1.9 -> satisfiable by symfony/symfony[v2.1.9].
- Installation request for symfony/symfony == 2.1.9999999.9999999-dev -> satisfiable by symfony/symfony[2.1.x-dev].
Can u help me plz ??
Thanks
I followed the documentation and got this error while the composer update command:
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The service definition "fos_user.registration.form.factory" does not exist.
I'm using Symfony 2.3.
I added this to my composer.json:
...
"friendsofsymfony/user-bundle": "2.0.*@dev",
"pugx/multi-user-bundle": "3.0.*@dev"
...
and added this to my AppKernel.php:
new PUGX\MultiUserBundle\PUGXMultiUserBundle(),
and got the error while composer are clearing the dev cache.
Any idea ?
Hi !
I recently succeeded to install FOSFacebookBundle with FOSUserbundle. But with PUGXMultiUserBundle it does not work. Did somebody already had this problem ? When I click on login with Facebook, I am redirected to /login but nothing happens. I'm relatively new to Symfony and I really don't know how to fix this !
Thank you,
Victor.
The original version of the function "findUsers" doesn't work.
public function findUsers()
{
$classes = $this->userDiscriminator->getClasses();
$users = array();
foreach ($classes as $class) {
$repo = $this->om->getRepository($class);
// in this line all already retrieved users get deleted from the array
$users = $repo->findAll();
if ($users) {
$users = array_merge($users, $users);
}
}
return $users;
}
This function works
public function findUsers()
{
$classes = $this->userDiscriminator->getClasses();
$usersAll = array(); // $usersAll
foreach ($classes as $class) {
$repo = $this->om->getRepository($class);
$users = $repo->findAll();
if ($users) {
$usersAll = array_merge($usersAll, $users); // $usersAll
}
}
return $usersAll; // $usersAll
}
regards,
Michael
Hi all you guys!!
I need to implementate a Customer, Seller and Admin user management. After search in different forums I found the PUGXMultiUserBundle and after read this solve issue #12 I had some hopes for do this with SonataUserBundle.
So, I have tried to adapt the PUGXMultiUserBundle with Sonata but I always get some problems with the composer update. If I use the next configuration on my composer.json file I get ' The service definition "fos_user.registration.form.factory" does not exist.'
"php": ">=5.3.3",
"symfony/symfony": "2.2.",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "1.2.",
"twig/extensions": "1.0.",
"symfony/assetic-bundle": "2.1.",
"symfony/swiftmailer-bundle": "2.2.",
"symfony/monolog-bundle": "2.2.",
"sensio/distribution-bundle": "2.2.",
"sensio/framework-extra-bundle": "2.2.",
"sensio/generator-bundle": "2.2.",
"jms/security-extra-bundle": "1.4.",
"jms/di-extra-bundle": "1.3.",
"doctrine/doctrine-fixtures-bundle": "dev-master",
"doctrine/data-fixtures": "dev-master",
"knplabs/knp-menu": "v1.1.2",
"knplabs/knp-menu-bundle": "1.1.x-dev",
"friendsofsymfony/user-bundle": "",
"sonata-project/intl-bundle":"",
"sonata-project/cache-bundle":"",
"sonata-project/admin-bundle": "",
"sonata-project/user-bundle": "~2.0@dev",
"sonata-project/media-bundle": "dev-master",
"sonata-project/doctrine-orm-admin-bundle": "2.2.x-dev",
"simplethings/entity-audit-bundle":"@dev"
But If I change the composer.json file following the recommendation in #21
{
"require": {
"friendsofsymfony/user-bundle": "2.0.@dev",
"pugx/multi-user-bundle": "2.0.@dev"
}
}
When I run the composer update then I get the next problems
Problem 1
- Installation request for sonata-project/user-bundle 2.0.@dev -> satisfiab
le by sonata-project/user-bundle[2.0.x-dev].
- sonata-project/user-bundle 2.0.x-dev requires sonata-project/admin-bundle
2.0. -> no matching package found.
Problem 2
- Installation request for pugx/multi-user-bundle 2.0.@dev -> satisfiable b
y pugx/multi-user-bundle[2.0.x-dev].
- pugx/multi-user-bundle 2.0.x-dev requires friendsofsymfony/user-bundle 2.0
.x-dev -> no matching package found.
Problem 3
- sonata-project/user-bundle 2.0.x-dev requires sonata-project/admin-bundle
2.0. -> no matching package found.
- symfony/framework-standard-edition 2.2.x-dev requires sonata-project/user-
bundle 2.0.*@dev -> satisfiable by sonata-project/user-bundle[2.0.x-dev].
- Installation request for symfony/framework-standard-edition 2.2.x-dev -> s
atisfiable by symfony/framework-standard-edition[2.2.x-dev].
Potential causes:
Read http://getcomposer.org/doc/articles/troubleshooting.md for further common
problems.
Do you have any idea if is possible to integrate the PUGXMultiUserBundle with SonataUserBundle?
I really will appreciate your help, Thanks for your time
hi all,
I'm stuck and not solving the problem. I have correctly configured PUGXMultiUserBundle and I just need to make the profile Edit work of my class client work plz here it's my class
Hi Everybody,
Please i am a new symfony developper and i have a problem when i try to add a new user.
I created my own form as indicating in FOSUserBundle. I also redifined my own controller as indicating in PUGXMultiUserBundle i see correctly the custom form but when i click on the save button nothing. The table is empty the browser send the request and display the same form.
Please someone could tell me where the problem is ? I have this problem since one week.
After following the steps in the documentation whenever i go to the /register/client route i get this :
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "fos_user_registration_register" as such route does not exist.") in FOSUserBundle:Registration:register.html.twig at line 4.
The only way i could solve this was by uncommenting the registration route of FOSUB but i don't think it should be like this.
Here is my config for the client type user:
pugx_multi_user:
users:
client_user:
entity:
class: Acme\UserBundle\Entity\ClientUser
registration:
form:
type: Acme\UserBundle\Form\Type\ClientRegistrationFormType
name: fos_user_registration_form
validation_groups: [Registration, Default]
template: AcmeUserBundle:Registration:client.form.html.twig
profile:
form:
type: Acme\UserBundle\Form\Type\ClientProfileFormType
name: fos_user_profile_form
validation_groups: [Profile, Default]
I can see registration and profile, but resetting and security has not configuration or managers.
This bundle can be used in production?
PUGX/PUGXAutoCompleterBundle#1
I am having trouble making the profile Edit work.
Mainly one of two issues seems to occur:
That is what happens if try to access /profile/edit of the FOS User Bundle
Here is the code regarding that.... any help would be greatly appreciated.
<?php
namespace MHO\VmpBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller as BaseController;
use Symfony\Component\HttpFoundation\RedirectResponse;
class ProfileVmpPhysicianController extends BaseController
{
public function editAction()
{
$discriminator = $this->container->get('pugx_user_discriminator');
$discriminator->setClass('MHO\VmpBundle\Entity\VmpPhysician',$persist = true);
$form = $discriminator->getProfileForm();
$this->container->set('fos_user.profile.form', $form);
return $this->container->get('templating')->renderResponse('MHOVmpBundle:Profile:profile_vmp_physician.html.twig', array(
'form' => $form->createView(),
));
}
}
and here my form type class:
<?php
namespace MHO\VmpBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use FOS\UserBundle\Form\Type\ProfileFormType as BaseType;
class ProfileVmpPhysicianFormType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder
->add("username", "text", array( 'attr' => array(
'readonly' =>'readonly',
'class' => 'form-disabled' )))
->add("email", "email", array( 'attr' => array(
'readonly' =>'readonly',
'class' => 'form-disabled' )))
->add("firstname", "text", array( 'attr' => array(
'readonly' =>'readonly',
'class' => 'form-disabled' )))
->add("lastname", "text", array( 'attr' => array(
'readonly' =>'readonly',
'class' => 'form-disabled' )))
->add("middlename", "text", array(
'attr' => array('readonly' =>'readonly',
'class' => 'form-disabled' )))
->add('suffix', "text", array( 'attr' => array(
'readonly' =>'readonly',
'class' => 'form-disabled' )))
->add('homeAddress1', "text", array(
'label' => 'Address', ))
->add('homeAddress2', "text", array(
'label' => 'Address', 'required' => false, ))
->add('homeCity', "text", array(
'label' => 'City', ))
->add('homeState', "text", array(
'label' => 'State',))
->add('homeZipCode', 'text', array('pattern'=>'[0-9]{5}', 'label' => 'Zipcode', 'attr'=>array( 'maxlength' => '5')))
->add('officePhone', "text", array(
'label' => 'Office phone', ))
->add('fax')
->add('cellPhone', "text", array(
'label' => 'Mobile', ))
->add('npi', 'text', array('pattern'=>'[0-9]{10}', 'attr'=>array( 'maxlength' => '10')))
;
}
public function getName()
{
return 'fos_user_profile_form';
}
protected function buildUserForm(FormBuilderInterface $builder, array $options)
{
parent::buildUserForm($builder, $options);
}
}
Any ideas on what I could to get this to work?
It may be possible to enable custom user profile templates with the simple modification to Configuration.php as in the following excerpt:
->children()
->arrayNode('profile')
->addDefaultsIfNotSet()
->children()
->arrayNode('form')
->addDefaultsIfNotSet()
->children()
->scalarNode('type')->defaultValue(null)->end()
->scalarNode('name')->defaultValue('fos_user_profile_form')->end()
->arrayNode('validation_groups')
->prototype('scalar')->end()
->defaultValue(array('Profile', 'Default'))
->end()
->end()
->end()
->scalarNode('template')->defaultValue(null)->end()
->end()
->end()
->end()
Custom templates are possible with this modification and extending FOSUserBundle to allow the use of a custom ProfileController like the following:
class ProfileController extends BaseController
{
/**
* Edit the user
*/
public function editAction(Request $request)
{
$user = $this->container->get('security.context')->getToken()->getUser();
if (!is_object($user) || !$user instanceof UserInterface) {
throw new AccessDeniedException('This user does not have access to this section.');
}
$discriminator = $this->container->get('pugx_user.manager.user_discriminator');
$users = $this->container->getParameter('pugx_user_discriminator_users');
$class = $discriminator->getClass($user);
foreach ($users as $userType) {
if ($userType['entity']['class'] == $class) {
$templateString = $userType['profile']['template'];
if (false === strpos($templateString, $this->container->getParameter('fos_user.template.engine'))) {
$template = 'FOSUserBundle:Profile:edit.html.';
} else {
$l = strrpos($templateString, ".");
$template = substr($templateString, 0, $l + 1);
}
}
}
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
$dispatcher = $this->container->get('event_dispatcher');
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
$formFactory = $this->container->get('fos_user.profile.form.factory');
$form = $formFactory->createForm();
$form->setData($user);
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->container->get('fos_user.user_manager');
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->container->get('router')->generate('fos_user_profile_show');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::PROFILE_EDIT_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
return $response;
}
}
return $this->container->get('templating')->renderResponse(
$template . $this->container->getParameter('fos_user.template.engine'), array('form' => $form->createView())
);
}
This has all been at the limit of my skill set, so if it's out of place please let me know. But it was fun figuring it out.
Edit: I suspect there is much more to this request than originally thought. Ignore the above if it is deemed dumb.
George
Hi,
I get the error below when trying to send the form theme to the twig template
The parameter "fos_user.template.theme" must be defined.
Resulting from this code below:
return $this->container->get('templating')->renderResponse('MHOVmpBundle:Registration:register_vmp_patient.html.twig', array(
'form' => $form->createView(),
'theme' => $this->container->getParameter('fos_user.template.theme'),
));
Also, if in the twig file I try to call {% form_theme form theme %} I also get an error saying that the variable theme is not defined.
Does the FOSUserBundle latest dev-master lead to this issue?
Hello, I was wondering how to get the same result as the views of the inscription, but the profile (view and edit).
Thanks.
Hi,
Thank you for your great work.
I think there is a problem with the AutenticationListener
and the setClass
method of the UserDiscriminator
.
Indeed, in case of a configured chained provider, with a mix of in_memory users
, PUGXUsers
and other custom providers
, login fails because of this listener, or even for the use of another simple provider. Example for in_memory user:
Impossible to set the class discriminator, because the class "Symfony\Component\Security\Core\User\User" is not present in the entities list
with the following security conf :
providers:
fos_users:
id: fos_user.user_provider.username_email
admin:
memory:
users:
- { name: %main_admin_login%, password: %main_admin_password%, roles: ['ROLE_ADMIN', 'ROLE_SUPER_ADMIN'] }
application:
id: acme.application.provider
chained_provider:
chain:
providers:
- admin
- fos_users
- application
The incriminated method is :
protected function discriminate($user)
{
$this->userDiscriminator->setClass(get_class($user), true);
}
This method is called on every login & switch user events, and generates an exception if the user type isn't one of the configured PUGX users, with a discriminator. Basically, this means it will fail on every login attempt with another user type, with a chained or any other provider, which I consider isn't a good way to achieve what this bundle is meant for : allow users inheritance. This should not alter the basic symfony's functionnalities.
Maybe the LogicException thrown by the UserDiscriminator::setClass
method should be catch in this listener ?
Is this LogicException really usefull ? For which cases ?
Is this AutenticationListener even necessary ? Isn't the discriminator set by the UserManager ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.