]>
Commit | Line | Data |
---|---|---|
6894d48e | 1 | <?php |
4346a860 | 2 | |
6894d48e J |
3 | namespace Wallabag\CoreBundle\Form\Type; |
4 | ||
5 | use Symfony\Component\Form\AbstractType; | |
6 | use Symfony\Component\Form\FormBuilderInterface; | |
7 | use Symfony\Component\Validator\Constraints; | |
8 | use Symfony\Component\Validator\ExecutionContextInterface; | |
9 | use Doctrine\Bundle\DoctrineBundle\Registry; | |
10 | ||
11 | class 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( | |
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 | ||
50 | ); | |
51 | } | |
52 | } | |
53 | } |