vendor/bundles/FOS/UserBundle/Form/Handler/ResettingFormHandler.php
changeset 3 e54dfe4d0b2b
equal deleted inserted replaced
2:806e57d67020 3:e54dfe4d0b2b
       
     1 <?php
       
     2 
       
     3 /*
       
     4  * This file is part of the FOSUserBundle package.
       
     5  *
       
     6  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
       
     7  *
       
     8  * For the full copyright and license information, please view the LICENSE
       
     9  * file that was distributed with this source code.
       
    10  */
       
    11 
       
    12 namespace FOS\UserBundle\Form\Handler;
       
    13 
       
    14 use Symfony\Component\Form\Form;
       
    15 use Symfony\Component\HttpFoundation\Request;
       
    16 
       
    17 use FOS\UserBundle\Model\UserInterface;
       
    18 use FOS\UserBundle\Model\UserManagerInterface;
       
    19 use FOS\UserBundle\Form\Model\ResetPassword;
       
    20 
       
    21 class ResettingFormHandler
       
    22 {
       
    23     protected $request;
       
    24     protected $userManager;
       
    25     protected $form;
       
    26 
       
    27     public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
       
    28     {
       
    29         $this->form = $form;
       
    30         $this->request = $request;
       
    31         $this->userManager = $userManager;
       
    32     }
       
    33 
       
    34     public function getNewPassword()
       
    35     {
       
    36         return $this->form->getData()->new;
       
    37     }
       
    38 
       
    39     public function process(UserInterface $user)
       
    40     {
       
    41         $this->form->setData(new ResetPassword());
       
    42 
       
    43         if ('POST' == $this->request->getMethod()) {
       
    44             $this->form->bindRequest($this->request);
       
    45 
       
    46             if ($this->form->isValid()) {
       
    47                 $this->onSuccess($user);
       
    48 
       
    49                 return true;
       
    50             }
       
    51         }
       
    52 
       
    53         return false;
       
    54     }
       
    55 
       
    56     protected function onSuccess(UserInterface $user)
       
    57     {
       
    58         $user->setPlainPassword($this->getNewPassword());
       
    59         $user->setConfirmationToken(null);
       
    60         $user->setEnabled(true);
       
    61         $this->userManager->updateUser($user);
       
    62     }
       
    63 }