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