diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php new file mode 100644 index 00000000..c278b84f --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php | |||
@@ -0,0 +1,52 @@ | |||
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 | 'constraints' => array( | ||
24 | new Constraints\Email(), | ||
25 | new Constraints\NotBlank(), | ||
26 | new Constraints\Callback(array(array($this, 'validateEmail'))), | ||
27 | ), | ||
28 | )) | ||
29 | ; | ||
30 | } | ||
31 | |||
32 | public function getName() | ||
33 | { | ||
34 | return 'forgot_password'; | ||
35 | } | ||
36 | |||
37 | public function validateEmail($email, ExecutionContextInterface $context) | ||
38 | { | ||
39 | $user = $this->doctrine | ||
40 | ->getRepository('WallabagCoreBundle:User') | ||
41 | ->findOneByEmail($email); | ||
42 | |||
43 | if (!$user) { | ||
44 | $context->addViolationAt( | ||
45 | 'email', | ||
46 | 'No user found with this email', | ||
47 | array(), | ||
48 | |||
49 | ); | ||
50 | } | ||
51 | } | ||
52 | } | ||