|
|
|
@ -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()) |
|
|
|
|