Skip to content
This repository was archived by the owner on Dec 14, 2021. It is now read-only.

Commit ebffc4c

Browse files
authored
Merge pull request #1620 from ojs/feature/disposable-email
Feature/disposable email blocker on registeration
2 parents 0a690bc + 1c04661 commit ebffc4c

7 files changed

Lines changed: 67 additions & 15 deletions

File tree

app/Resources/translations/validators.en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ title.field.article.files.not.be.blank: 'Title fields of article files can not b
2323
file.field.article.files.not.be.blank: 'File fields of article files can not be blank.'
2424
user.multiple_mail.invalid: 'This email is already registered'
2525
user.multiple_mail.error.not_email: 'You must enter a valid email'
26-
article.status_can_not_be_published_without_author: 'You must to add author before pull article status to published'
26+
article.status_can_not_be_published_without_author: 'You must to add author before pull article status to published'
27+
user.invalid.mail.domain: 'Mail have banned domain address'

app/Resources/translations/validators.tr.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ file.field.article.files.not.be.blank: 'Makale dosyası için file alanı boş o
2424
user.multiple_mail.invalid: 'Girdiğiniz adres zaten sistemde kayıtlı'
2525
user.multiple_mail.error.not_email: 'Geçerli e-mail adresi girmelisiniz'
2626
article.status_can_not_be_published_without_author: 'Makale durumunu yayınlandıya almadan önce makale yazarı eklemelisiniz.'
27+
user.invalid.mail.domain: 'E-posta adresi yasaklı bir alan adı'

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@
9494
"openjournalsoftware/bibtex": "~0.2",
9595
"exercise/htmlpurifier-bundle": "~0.2",
9696
"ojs/export-bundle": "dev-master",
97-
"willdurand/js-translation-bundle": "^2.5"
97+
"willdurand/js-translation-bundle": "^2.5",
98+
"contentfarm/disposable-email-list":"dev-master"
9899
},
99100
"require-dev": {
100101
"wdalmut/php-deb-packager": "^0.0.13",

src/Ojs/UserBundle/Controller/RegistrationController.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
use FOS\UserBundle\Event\FilterUserResponseEvent;
77
use FOS\UserBundle\Event\FormEvent;
88
use FOS\UserBundle\Event\GetResponseUserEvent;
9+
use FOS\UserBundle\Form\Factory\FactoryInterface;
910
use FOS\UserBundle\FOSUserEvents;
11+
use FOS\UserBundle\Model\UserManagerInterface;
1012
use FOS\UserBundle\Util\TokenGenerator;
1113
use Ojs\UserBundle\Entity\User;
1214
use Ojs\UserBundle\Event\UserEvent;
15+
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1316
use Symfony\Component\HttpFoundation\RedirectResponse;
1417
use Symfony\Component\HttpFoundation\Request;
1518

@@ -26,19 +29,16 @@ public function registerAction(Request $request)
2629
]
2730
);
2831
}
29-
30-
/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
32+
/** @var $formFactory FactoryInterface */
3133
$formFactory = $this->get('fos_user.registration.form.factory');
32-
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
34+
/** @var $userManager UserManagerInterface */
3335
$userManager = $this->get('ojs_user.manager');
34-
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
36+
/** @var $dispatcher EventDispatcherInterface */
3537
$dispatcher = $this->get('event_dispatcher');
3638

3739
/** @var User $user */
3840
$user = $userManager->createUser();
3941
$user->setEnabled(true);
40-
//Add default data for oauth login
41-
$session = $this->get('session');
4242

4343
$event = new GetResponseUserEvent($user, $request);
4444
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, $event);
@@ -68,9 +68,7 @@ public function registerAction(Request $request)
6868

6969
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
7070

71-
$session->getFlashBag()->add('success', 'registration.activation');
72-
73-
$session->save();
71+
$this->addFlash('success', 'registration.activation');
7472

7573
$event = new UserEvent($user);
7674
$dispatcher = $this->get('event_dispatcher');
@@ -79,11 +77,9 @@ public function registerAction(Request $request)
7977
return $response;
8078
}
8179

82-
return $this->render(
83-
'OjsUserBundle:Registration:register.html.twig',
84-
array(
80+
return $this->render('OjsUserBundle:Registration:register.html.twig', [
8581
'form' => $form->createView(),
86-
)
82+
]
8783
);
8884
}
8985
}

src/Ojs/UserBundle/Resources/config/validation/User.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Ojs\UserBundle\Entity\User:
3131
- NotBlank: { groups: [Default, ojs_register, editProfile, journal_user] }
3232
- Email: { groups: [Default, ojs_register, editProfile, journal_user] }
3333
- Ojs\UserBundle\Validator\Constraints\UniqueMultipleEmails: { message: 'user.multiple_mail.invalid', groups: [ojs_register, journal_user] }
34+
- Ojs\UserBundle\Validator\Constraints\DisposableEmail: { message: 'user.invalid.mail.domain', groups: [ojs_register, journal_user] }
3435
firstName:
3536
- NotBlank: { groups: [Default, ojs_register, editProfile, journal_user] }
3637
lastName:
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Ojs\UserBundle\Validator\Constraints;
4+
5+
use Ojs\UserBundle\Validator\DisposableEmailValidator;
6+
use Symfony\Component\Validator\Constraints\Email;
7+
8+
/**
9+
* @Annotation
10+
*/
11+
class DisposableEmail extends Email
12+
{
13+
public $message = 'One or more of emails are not available or valid domain.';
14+
15+
public function validatedBy()
16+
{
17+
return DisposableEmailValidator::class;
18+
}
19+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
4+
namespace Ojs\UserBundle\Validator;
5+
6+
use ContentFarm\DisposableEmail\DisposableEmailService;
7+
use Ojs\UserBundle\Validator\Constraints\DisposableEmail;
8+
use Symfony\Component\Validator\Constraint;
9+
use Symfony\Component\Validator\ConstraintValidator;
10+
11+
/**
12+
* @Annotation
13+
*/
14+
class DisposableEmailValidator extends ConstraintValidator
15+
{
16+
/**
17+
* @param mixed $value
18+
* @param Constraint|DisposableEmail $constraint
19+
* @return mixed
20+
*/
21+
public function validate($value, Constraint $constraint)
22+
{
23+
24+
$disposableEmailService = new DisposableEmailService();
25+
$disposableEmailService->mail = $value;
26+
27+
28+
if ($disposableEmailService->isDisposableEmail()) {
29+
$this->context->addViolation($constraint->message);
30+
}
31+
32+
}
33+
}

0 commit comments

Comments
 (0)