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

Commit

Permalink
Merge pull request #1620 from ojs/feature/disposable-email
Browse files Browse the repository at this point in the history
Feature/disposable email blocker on registeration
  • Loading branch information
behram authored Oct 29, 2016
2 parents 0a690bc + 1c04661 commit ebffc4c
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 15 deletions.
3 changes: 2 additions & 1 deletion app/Resources/translations/validators.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ title.field.article.files.not.be.blank: 'Title fields of article files can not b
file.field.article.files.not.be.blank: 'File fields of article files can not be blank.'
user.multiple_mail.invalid: 'This email is already registered'
user.multiple_mail.error.not_email: 'You must enter a valid email'
article.status_can_not_be_published_without_author: 'You must to add author before pull article status to published'
article.status_can_not_be_published_without_author: 'You must to add author before pull article status to published'
user.invalid.mail.domain: 'Mail have banned domain address'
1 change: 1 addition & 0 deletions app/Resources/translations/validators.tr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ file.field.article.files.not.be.blank: 'Makale dosyası için file alanı boş o
user.multiple_mail.invalid: 'Girdiğiniz adres zaten sistemde kayıtlı'
user.multiple_mail.error.not_email: 'Geçerli e-mail adresi girmelisiniz'
article.status_can_not_be_published_without_author: 'Makale durumunu yayınlandıya almadan önce makale yazarı eklemelisiniz.'
user.invalid.mail.domain: 'E-posta adresi yasaklı bir alan adı'
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
"openjournalsoftware/bibtex": "~0.2",
"exercise/htmlpurifier-bundle": "~0.2",
"ojs/export-bundle": "dev-master",
"willdurand/js-translation-bundle": "^2.5"
"willdurand/js-translation-bundle": "^2.5",
"contentfarm/disposable-email-list":"dev-master"
},
"require-dev": {
"wdalmut/php-deb-packager": "^0.0.13",
Expand Down
22 changes: 9 additions & 13 deletions src/Ojs/UserBundle/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
use FOS\UserBundle\Event\FilterUserResponseEvent;
use FOS\UserBundle\Event\FormEvent;
use FOS\UserBundle\Event\GetResponseUserEvent;
use FOS\UserBundle\Form\Factory\FactoryInterface;
use FOS\UserBundle\FOSUserEvents;
use FOS\UserBundle\Model\UserManagerInterface;
use FOS\UserBundle\Util\TokenGenerator;
use Ojs\UserBundle\Entity\User;
use Ojs\UserBundle\Event\UserEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -26,19 +29,16 @@ public function registerAction(Request $request)
]
);
}

/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
/** @var $formFactory FactoryInterface */
$formFactory = $this->get('fos_user.registration.form.factory');
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
/** @var $userManager UserManagerInterface */
$userManager = $this->get('ojs_user.manager');
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
/** @var $dispatcher EventDispatcherInterface */
$dispatcher = $this->get('event_dispatcher');

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

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

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

$session->getFlashBag()->add('success', 'registration.activation');

$session->save();
$this->addFlash('success', 'registration.activation');

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

return $this->render(
'OjsUserBundle:Registration:register.html.twig',
array(
return $this->render('OjsUserBundle:Registration:register.html.twig', [
'form' => $form->createView(),
)
]
);
}
}
1 change: 1 addition & 0 deletions src/Ojs/UserBundle/Resources/config/validation/User.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Ojs\UserBundle\Entity\User:
- NotBlank: { groups: [Default, ojs_register, editProfile, journal_user] }
- Email: { groups: [Default, ojs_register, editProfile, journal_user] }
- Ojs\UserBundle\Validator\Constraints\UniqueMultipleEmails: { message: 'user.multiple_mail.invalid', groups: [ojs_register, journal_user] }
- Ojs\UserBundle\Validator\Constraints\DisposableEmail: { message: 'user.invalid.mail.domain', groups: [ojs_register, journal_user] }
firstName:
- NotBlank: { groups: [Default, ojs_register, editProfile, journal_user] }
lastName:
Expand Down
19 changes: 19 additions & 0 deletions src/Ojs/UserBundle/Validator/Constraints/DisposableEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Ojs\UserBundle\Validator\Constraints;

use Ojs\UserBundle\Validator\DisposableEmailValidator;
use Symfony\Component\Validator\Constraints\Email;

/**
* @Annotation
*/
class DisposableEmail extends Email
{
public $message = 'One or more of emails are not available or valid domain.';

public function validatedBy()
{
return DisposableEmailValidator::class;
}
}
33 changes: 33 additions & 0 deletions src/Ojs/UserBundle/Validator/DisposableEmailValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php


namespace Ojs\UserBundle\Validator;

use ContentFarm\DisposableEmail\DisposableEmailService;
use Ojs\UserBundle\Validator\Constraints\DisposableEmail;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;

/**
* @Annotation
*/
class DisposableEmailValidator extends ConstraintValidator
{
/**
* @param mixed $value
* @param Constraint|DisposableEmail $constraint
* @return mixed
*/
public function validate($value, Constraint $constraint)
{

$disposableEmailService = new DisposableEmailService();
$disposableEmailService->mail = $value;


if ($disposableEmailService->isDisposableEmail()) {
$this->context->addViolation($constraint->message);
}

}
}

0 comments on commit ebffc4c

Please sign in to comment.