]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php
4cc16a501a28c4a93453b0881fb6718d9bf8cafe
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Form / Type / ForgotPasswordType.php
1 <?php
2 namespace Wallabag\CoreBundle\Form\Type;
3
4 use Symfony\Component\Form\AbstractType;
5 use Symfony\Component\Form\FormBuilderInterface;
6 use Symfony\Component\Validator\Constraints;
7 use Symfony\Component\Validator\ExecutionContextInterface;
8 use Doctrine\Bundle\DoctrineBundle\Registry;
9
10 class ForgotPasswordType extends AbstractType
11 {
12 private $doctrine = null;
13
14 public function __construct(Registry $doctrine)
15 {
16 $this->doctrine = $doctrine;
17 }
18
19 public function buildForm(FormBuilderInterface $builder, array $options)
20 {
21 $builder
22 ->add('email', 'email', array(
23 'required' => true,
24 'constraints' => array(
25 new Constraints\Email(),
26 new Constraints\NotBlank(),
27 new Constraints\Callback(array(array($this, 'validateEmail'))),
28 ),
29 ))
30 ;
31 }
32
33 public function getName()
34 {
35 return 'forgot_password';
36 }
37
38 public function validateEmail($email, ExecutionContextInterface $context)
39 {
40 $user = $this->doctrine
41 ->getRepository('WallabagCoreBundle:User')
42 ->findOneByEmail($email);
43
44 if (!$user) {
45 $context->addViolationAt(
46 'email',
47 'No user found with this email',
48 array(),
49 $email
50 );
51 }
52 }
53 }