Handle forgot password

This commit is contained in:
Jeremy
2015-03-07 23:25:36 +01:00
parent f37d1427a1
commit 6894d48e03
15 changed files with 481 additions and 8 deletions

View File

@ -0,0 +1,52 @@
<?php
namespace Wallabag\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints;
use Symfony\Component\Validator\ExecutionContextInterface;
use Doctrine\Bundle\DoctrineBundle\Registry;
class ForgotPasswordType extends AbstractType
{
private $doctrine = null;
public function __construct(Registry $doctrine)
{
$this->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
);
}
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace Wallabag\CoreBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints;
class ResetPasswordType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->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';
}
}