aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Form
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2015-03-30 17:05:37 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2015-03-30 17:05:37 +0200
commitf98a2a0fc3ae8a5955bb811f083c3d2535f96791 (patch)
tree386ecf0a54bdf904225182e0d2f63ced417b32c5 /src/Wallabag/CoreBundle/Form
parentbdf2add2e80dc52a02113c50636b5f887639b31a (diff)
parentd0c2243b1099303be961c9d4b33eaaa95e663bef (diff)
downloadwallabag-f98a2a0fc3ae8a5955bb811f083c3d2535f96791.tar.gz
wallabag-f98a2a0fc3ae8a5955bb811f083c3d2535f96791.tar.zst
wallabag-f98a2a0fc3ae8a5955bb811f083c3d2535f96791.zip
Merge pull request #1152 from wallabag/v2-forgot-password
Handle forgot password
Diffstat (limited to 'src/Wallabag/CoreBundle/Form')
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php52
-rw-r--r--src/Wallabag/CoreBundle/Form/Type/ResetPasswordType.php34
2 files changed, 86 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
2namespace Wallabag\CoreBundle\Form\Type;
3
4use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\FormBuilderInterface;
6use Symfony\Component\Validator\Constraints;
7use Symfony\Component\Validator\ExecutionContextInterface;
8use Doctrine\Bundle\DoctrineBundle\Registry;
9
10class 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 $email
49 );
50 }
51 }
52}
diff --git a/src/Wallabag/CoreBundle/Form/Type/ResetPasswordType.php b/src/Wallabag/CoreBundle/Form/Type/ResetPasswordType.php
new file mode 100644
index 00000000..50ae800b
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Form/Type/ResetPasswordType.php
@@ -0,0 +1,34 @@
1<?php
2namespace Wallabag\CoreBundle\Form\Type;
3
4use Symfony\Component\Form\AbstractType;
5use Symfony\Component\Form\FormBuilderInterface;
6use Symfony\Component\Validator\Constraints;
7
8class ResetPasswordType extends AbstractType
9{
10 public function buildForm(FormBuilderInterface $builder, array $options)
11 {
12 $builder
13 ->add('new_password', 'repeated', array(
14 'type' => 'password',
15 'invalid_message' => 'The password fields must match.',
16 'required' => true,
17 'first_options' => array('label' => 'New password'),
18 'second_options' => array('label' => 'Repeat new password'),
19 'constraints' => array(
20 new Constraints\Length(array(
21 'min' => 8,
22 'minMessage' => 'Password should by at least 8 chars long',
23 )),
24 new Constraints\NotBlank(),
25 ),
26 ))
27 ;
28 }
29
30 public function getName()
31 {
32 return 'change_passwd';
33 }
34}