From 6894d48e03c397096bb64420373afa60c397fe97 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Sat, 7 Mar 2015 23:25:36 +0100 Subject: Handle forgot password --- .../CoreBundle/Form/Type/ForgotPasswordType.php | 52 ++++++++++++++++++++++ .../CoreBundle/Form/Type/ResetPasswordType.php | 34 ++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/Wallabag/CoreBundle/Form/Type/ForgotPasswordType.php create mode 100644 src/Wallabag/CoreBundle/Form/Type/ResetPasswordType.php (limited to 'src/Wallabag/CoreBundle/Form/Type') 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 @@ +doctrine = $doctrine; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('email', 'email', array( + 'constraints' => array( + new Constraints\Email(), + new Constraints\NotBlank(), + new Constraints\Callback(array(array($this, 'validateEmail'))), + ), + )) + ; + } + + public function getName() + { + return 'forgot_password'; + } + + public function validateEmail($email, ExecutionContextInterface $context) + { + $user = $this->doctrine + ->getRepository('WallabagCoreBundle:User') + ->findOneByEmail($email); + + if (!$user) { + $context->addViolationAt( + 'email', + 'No user found with this email', + array(), + $email + ); + } + } +} 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 @@ +add('new_password', 'repeated', array( + 'type' => 'password', + 'invalid_message' => 'The password fields must match.', + 'required' => true, + 'first_options' => array('label' => 'New password'), + 'second_options' => array('label' => 'Repeat new password'), + 'constraints' => array( + new Constraints\Length(array( + 'min' => 8, + 'minMessage' => 'Password should by at least 8 chars long', + )), + new Constraints\NotBlank(), + ), + )) + ; + } + + public function getName() + { + return 'change_passwd'; + } +} -- cgit v1.2.3