diff --git a/EventListener/RegistrationHandlerListener.php b/EventListener/RegistrationHandlerListener.php index 6029145..343e2d1 100644 --- a/EventListener/RegistrationHandlerListener.php +++ b/EventListener/RegistrationHandlerListener.php @@ -28,6 +28,8 @@ use vierbergenlars\AuthserverOAuthAccountBundle\Entity\TemporaryUser; use Doctrine\ORM\EntityManagerInterface; use App\Entity\EmailAddress; use vierbergenlars\AuthserverOAuthAccountBundle\ResourceOwner\ResourceOwnerMap; +use EmailRulesBundle\EmailHandler\EmailRules; +use Registration\RegistrationHandler\RegistrationRules; class RegistrationHandlerListener implements EventSubscriberInterface { @@ -50,6 +52,18 @@ class RegistrationHandlerListener implements EventSubscriberInterface */ private $resourceOwnerMap; + /** + * + * @var EmailRules|null + */ + private $emailRules; + + /** + * + * @var RegistrationRules|null + */ + private $registrationRules; + public static function getSubscribedEvents() { return [ @@ -64,11 +78,13 @@ class RegistrationHandlerListener implements EventSubscriberInterface ]; } - public function __construct(EntityManagerInterface $em, TokenStorageInterface $tokenStorage, ResourceOwnerMap $resourceOwnerMap) + public function __construct(EntityManagerInterface $em, TokenStorageInterface $tokenStorage, ResourceOwnerMap $resourceOwnerMap, EmailRules $emailRules = null, RegistrationRules $registrationRules = null) { $this->em = $em; $this->tokenStorage = $tokenStorage; $this->resourceOwnerMap = $resourceOwnerMap; + $this->emailRules = $emailRules; + $this->registrationRules = $registrationRules; } private function getTemporaryUser() @@ -86,6 +102,20 @@ class RegistrationHandlerListener implements EventSubscriberInterface { if ($tempuser = $this->getTemporaryUser()) { if ($tempuser->getEmail()) { + if ($this->emailRules) { + $rule = $this->emailRules->getFirstRuleMatching($tempuser->getEmail()); + if ($rule && $rule->isReject()) { + // Do not fill in an email address that will get rejected anyways. + return; + } + } + if ($this->registrationRules) { + $rule = $this->registrationRules->getFirstRuleMatching($tempuser->getEmail()); + if (!$rule || !$rule->isSelfRegistration()) { + // Do not fill in an email address that is not elegible for self registration. + return; + } + } $user = $event->getFormBuilder()->getData(); /* @var $user \App\Entity\User */ if (!$user->getPrimaryEmailAddress()) diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 9adf918..d127457 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -47,6 +47,8 @@ + +