Open djwatt3 opened 9 years ago
No, all the user-systems are interdependent, meaning they don't know of each others existence.
If you want something like this you need to create your own validator.
very well. I have created my validator that not allow multiple user with same username or email in the system. This is the constraint class:
namespace Rollerworks\Bundle\MultiUserBundle\Validator\Constraints;
use FOS\UserBundle\Model\UserManagerInterface;
use Rollerworks\Bundle\MultiUserBundle\Model\UserConfig;
use Rollerworks\Bundle\MultiUserBundle\Model\UserDiscriminatorInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/** Constraint Unique Email in all User-Systems. */
/** @Annotation */
class UniqueEmailSystemValidator extends ConstraintValidator {
private $userDiscriminator;
/** @param UserDiscriminatorInterface $userDiscriminator */
public function __construct(UserDiscriminatorInterface $userDiscriminator)
{
$this->userDiscriminator = $userDiscriminator;
}
public function validate($value, Constraint $constraint)
{
$usersInSystems = $this->userDiscriminator->getUsers();
$currentUserConfig = $this->userDiscriminator->getCurrentUserConfig();
/** @var UserConfig $userInSystem */
foreach($usersInSystems as $userInSystem) {
if ($userInSystem !== $currentUserConfig) {
/** @var UserManagerInterface $userDocumentManager */
$userDocumentManager = $userInSystem->getUserManager();
if ($userDocumentManager->findUserByEmail($value)) {
$this->buildViolation($constraint->message)
->setTranslationDomain('FOSUserBundle')
->addViolation();
}
}
}
}
}
I have added also new method in UserDiscriminator class, it is getUsers() that return all users present in the system. So i have added this constraint to field in my model class:
/** @MongoDB\UniqueIndex()
* @RollerworksAssert\UniqueEmailSystem(message="Email già esistente nel sistema") */
protected $email;
Done also unique login for all users. I select the correct user with requestMatcher class by Role identify. Thanks you
Please use the GitHub markdown code formatting. https://help.github.com/articles/markdown-basics/#code-formatting
I edited you reply to make it more readable.
Ok. Thank You
Is there a feature in the bundle, that allow to register one unique user for all user-system type? Thank You