Skip to content

Commit

Permalink
Se agregó restricción de registro por dominio
Browse files Browse the repository at this point in the history
  • Loading branch information
jogianotti committed Jun 25, 2019
1 parent 04b6be3 commit 7a5fcd8
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Celsius3/CoreBundle/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/Celsius3/CoreBundle/Helper/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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'),
]),
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
<target>forgot your password?</target>
<jms:reference-file line="51">/../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="invalid.email.domain" resname="invalid.email.domain">
<source>invalid.email.domain</source>
<target>The email domain is not valid. Use an email of %domain% domain</target>
</trans-unit>
<trans-unit id="The domain is not valid" resname="The domain is not valid">
<source>The domain is not valid</source>
<target>The domain is not valid</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
<target>olvidó su contraseña?</target>
<jms:reference-file line="51">/../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="invalid.email.domain" resname="invalid.email.domain">
<source>invalid.email.domain</source>
<target>Se debe registrar con un correo electrónico del dominio %domain%</target>
</trans-unit>
<trans-unit id="The domain is not valid" resname="The domain is not valid">
<source>The domain is not valid</source>
<target>El dominio no es valido</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@
<target>esqueceu a sua senha?</target>
<jms:reference-file line="51">/../src/Celsius3/CoreBundle/Resources/views/Security/login.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="invalid.email.domain" resname="invalid.email.domain">
<source>invalid.email.domain</source>
<target>O domínio de email não é válido. Use um email do domínio %domain%</target>
</trans-unit>
<trans-unit id="The domain is not valid" resname="The domain is not valid">
<source>The domain is not valid</source>
<target>O domínio não é válido</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -4110,6 +4110,10 @@
<source>responsible</source>
<target>responsible</target>
</trans-unit>
<trans-unit id="Email domain for registration" resname="Email domain for registration">
<source>Email domain for registration</source>
<target>Email domain for registration</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,10 @@
<source>responsible</source>
<target>Responsable</target>
</trans-unit>
<trans-unit id="Email domain for registration" resname="Email domain for registration">
<source>Email domain for registration</source>
<target>Dominio de correo electrónico para el registro</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -4109,6 +4109,10 @@
<source>responsible</source>
<target>Responsável</target>
</trans-unit>
<trans-unit id="Email domain for registration" resname="Email domain for registration">
<source>Email domain for registration</source>
<target>Domínio de email para registro</target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@
{{ form_row(configure_form.confirmation_type) }}
</div>
</div>
<div class="row">
<div class="col-md-12">
{{ form_row(configure_form.email_domain_for_registration) }}
</div>
</div>
<div class="row">
<div class="col-md-6">
{{ form_row(configure_form.min_days_for_send_mail) }}
Expand Down
38 changes: 38 additions & 0 deletions src/Celsius3/CoreBundle/Validator/Constraints/EmailDomain.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/*
* Celsius3 - Order management
* Copyright (C) 2014 PREBI-SEDICI <[email protected]> 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 <http://www.gnu.org/licenses/>.
*/

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';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* Celsius3 - Order management
* Copyright (C) 2014 PREBI-SEDICI <[email protected]> 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 <http://www.gnu.org/licenses/>.
*/

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();
}
}
}

0 comments on commit 7a5fcd8

Please sign in to comment.