From 7a5fcd825ea007f30962cbf4c42a9360a825a79c Mon Sep 17 00:00:00 2001 From: Jorge Oscar Gianotti Date: Tue, 25 Jun 2019 10:25:47 -0300 Subject: [PATCH] =?UTF-8?q?Se=20agreg=C3=B3=20restricci=C3=B3n=20de=20regi?= =?UTF-8?q?stro=20por=20dominio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/RegistrationController.php | 10 +++++ .../CoreBundle/Helper/ConfigurationHelper.php | 15 ++++++++ .../Celsius3CoreBundle_Form.en.xliff | 8 ++++ .../Celsius3CoreBundle_Form.es.xliff | 8 ++++ .../Celsius3CoreBundle_Form.pt.xliff | 8 ++++ .../Resources/translations/messages.en.xliff | 4 ++ .../Resources/translations/messages.es.xliff | 4 ++ .../Resources/translations/messages.pt.xliff | 4 ++ .../AdminInstance/configure_form.html.twig | 5 +++ .../Validator/Constraints/EmailDomain.php | 38 +++++++++++++++++++ .../Constraints/EmailDomainValidator.php | 36 ++++++++++++++++++ 11 files changed, 140 insertions(+) create mode 100644 src/Celsius3/CoreBundle/Validator/Constraints/EmailDomain.php create mode 100644 src/Celsius3/CoreBundle/Validator/Constraints/EmailDomainValidator.php diff --git a/src/Celsius3/CoreBundle/Controller/RegistrationController.php b/src/Celsius3/CoreBundle/Controller/RegistrationController.php index 8785ab284..ad57449a1 100644 --- a/src/Celsius3/CoreBundle/Controller/RegistrationController.php +++ b/src/Celsius3/CoreBundle/Controller/RegistrationController.php @@ -22,6 +22,7 @@ namespace Celsius3\CoreBundle\Controller; +use Symfony\Component\Form\FormError; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -58,6 +59,15 @@ public function registerAction(Request $request) if ('POST' === $request->getMethod()) { $form->handleRequest($request); + if ($email = $form->get('email')->getData()) { + $emailDomain = (strpos($email, '@')) ? explode('@', $email)[1] : ''; + $instanceDomain = $this->getInstance()->get('email_domain_for_registration')->getValue(); + if ($instanceDomain && $emailDomain && $emailDomain !== $instanceDomain) { + $error = new FormError($this->get('translator')->trans('invalid.email.domain', ['%domain%' => $instanceDomain], 'Celsius3CoreBundle_Form')); + $form->get('email')->addError($error); + } + } + if ($form->isValid()) { $event = new FormEvent($form, $request); $dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event); diff --git a/src/Celsius3/CoreBundle/Helper/ConfigurationHelper.php b/src/Celsius3/CoreBundle/Helper/ConfigurationHelper.php index 03f212832..020b6177a 100644 --- a/src/Celsius3/CoreBundle/Helper/ConfigurationHelper.php +++ b/src/Celsius3/CoreBundle/Helper/ConfigurationHelper.php @@ -23,6 +23,7 @@ namespace Celsius3\CoreBundle\Helper; use Celsius3\CoreBundle\Entity\Configuration; +use Celsius3\CoreBundle\Validator\Constraints\EmailDomain; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Validator\Constraints\Image; use Symfony\Component\Form\Extension\Core\Type\TextType; @@ -39,6 +40,7 @@ use Celsius3\CoreBundle\Form\Type\ConfirmationType; use Celsius3\CoreBundle\Form\Type\ResultsType; use Celsius3\CoreBundle\Form\Type\LogoSelectorType; +use Symfony\Component\Validator\Constraints\Email; class ConfigurationHelper { @@ -79,6 +81,7 @@ class ConfigurationHelper const CONF__HOME_INFORMATION_VISIBLE = 'home_information_visible'; const CONF__HOME_STATISTICS_VISIBLE = 'home_statistics_visible'; const CONF__HOME_HELP_VISIBLE = 'home_help_visible'; + const CONF__EMAIL_DOMAIN_FOR_REGISTRATION = 'email_domain_for_registration'; private $equivalences = array( 'string' => TextType::class, @@ -318,6 +321,12 @@ class ConfigurationHelper 'type' => 'boolean', 'required' => false, ), + self::CONF__EMAIL_DOMAIN_FOR_REGISTRATION => array( + 'name' => '', + 'value' => '', + 'type' => 'string', + 'required' => false, + ), ); private $container; @@ -430,5 +439,11 @@ private function configureConstraints() ); $this->configurations['instance_logo']['constraints'] = array($imageConstraints); + + $this->configurations[self::CONF__EMAIL_DOMAIN_FOR_REGISTRATION]['constraints'] = [ + new EmailDomain([ + 'message' => $this->container->get('translator')->trans('The domain is not valid', [], 'Celsius3CoreBundle_Form'), + ]), + ]; } } diff --git a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.en.xliff b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.en.xliff index da9ae42e1..14b9a668a 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.en.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.en.xliff @@ -88,6 +88,14 @@ forgot your password? /../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig + + invalid.email.domain + The email domain is not valid. Use an email of %domain% domain + + + The domain is not valid + The domain is not valid + diff --git a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.es.xliff b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.es.xliff index 199c6965d..86913cd1d 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.es.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.es.xliff @@ -88,6 +88,14 @@ olvidó su contraseña? /../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig + + invalid.email.domain + Se debe registrar con un correo electrónico del dominio %domain% + + + The domain is not valid + El dominio no es valido + diff --git a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.pt.xliff b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.pt.xliff index 44c220053..6e56b4dce 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.pt.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/Celsius3CoreBundle_Form.pt.xliff @@ -88,6 +88,14 @@ esqueceu a sua senha? /../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig + + invalid.email.domain + O domínio de email não é válido. Use um email do domínio %domain% + + + The domain is not valid + O domínio não é válido + diff --git a/src/Celsius3/CoreBundle/Resources/translations/messages.en.xliff b/src/Celsius3/CoreBundle/Resources/translations/messages.en.xliff index 32cbd38d3..05848ef54 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/messages.en.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/messages.en.xliff @@ -4110,6 +4110,10 @@ responsible responsible + + Email domain for registration + Email domain for registration + diff --git a/src/Celsius3/CoreBundle/Resources/translations/messages.es.xliff b/src/Celsius3/CoreBundle/Resources/translations/messages.es.xliff index 96f84ab85..3d1bfb231 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/messages.es.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/messages.es.xliff @@ -4115,6 +4115,10 @@ responsible Responsable + + Email domain for registration + Dominio de correo electrónico para el registro + diff --git a/src/Celsius3/CoreBundle/Resources/translations/messages.pt.xliff b/src/Celsius3/CoreBundle/Resources/translations/messages.pt.xliff index a4279b562..0b30592f0 100755 --- a/src/Celsius3/CoreBundle/Resources/translations/messages.pt.xliff +++ b/src/Celsius3/CoreBundle/Resources/translations/messages.pt.xliff @@ -4109,6 +4109,10 @@ responsible Responsável + + Email domain for registration + Domínio de email para registro + diff --git a/src/Celsius3/CoreBundle/Resources/views/AdminInstance/configure_form.html.twig b/src/Celsius3/CoreBundle/Resources/views/AdminInstance/configure_form.html.twig index 0d8772e09..4471106a8 100644 --- a/src/Celsius3/CoreBundle/Resources/views/AdminInstance/configure_form.html.twig +++ b/src/Celsius3/CoreBundle/Resources/views/AdminInstance/configure_form.html.twig @@ -177,6 +177,11 @@ {{ form_row(configure_form.confirmation_type) }} +
+
+ {{ form_row(configure_form.email_domain_for_registration) }} +
+
{{ form_row(configure_form.min_days_for_send_mail) }} diff --git a/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomain.php b/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomain.php new file mode 100644 index 000000000..e2e8cf3d0 --- /dev/null +++ b/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomain.php @@ -0,0 +1,38 @@ + http://prebi.unlp.edu.ar http://sedici.unlp.edu.ar + * + * This file is part of Celsius3. + * + * Celsius3 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Celsius3 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Celsius3. If not, see . + */ + +namespace Celsius3\CoreBundle\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; + +/** + * @Annotation + */ +class EmailDomain extends Constraint +{ + public $message = 'The domain is not valid'; + + public function validatedBy() + { + return get_class($this) . 'Validator'; + } +} diff --git a/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomainValidator.php b/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomainValidator.php new file mode 100644 index 000000000..9a70ed37b --- /dev/null +++ b/src/Celsius3/CoreBundle/Validator/Constraints/EmailDomainValidator.php @@ -0,0 +1,36 @@ + http://prebi.unlp.edu.ar http://sedici.unlp.edu.ar + * + * This file is part of Celsius3. + * + * Celsius3 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Celsius3 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Celsius3. If not, see . + */ + +namespace Celsius3\CoreBundle\Validator\Constraints; + +use Symfony\Component\Validator\Constraint; +use Symfony\Component\Validator\ConstraintValidator; + +class EmailDomainValidator extends ConstraintValidator +{ + public function validate($value, Constraint $constraint) + { + if (!checkdnsrr($value, "MX")) { + $this->context->buildViolation($constraint->message)->addViolation(); + } + } +}