public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('identifier');
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
         $data = $event->getData();
         if (!$data instanceof RequestPassword) {
             throw new \RuntimeException('RequestPassword instance required.');
         }
         $identifier = $data->getIdentifier();
         $form = $event->getForm();
         if (!$identifier || count($form->getErrors(true))) {
             return;
         }
         $user = $this->handler->getUserByIdentifier($identifier);
         if (null == $user) {
             $form->get('identifier')->addError(new FormError('User not present in our database'));
             return;
         } else {
             $data->setUser($user);
             if ($user->getIsAlreadyRequested() && null != $user->getConfirmationToken()) {
                 $form->get('identifier')->addError(new FormError('You already requested for a new password'));
                 return;
             }
         }
     });
 }
 /**
  * @param UserDataEvent $event
  */
 public function onRequestedPassword(UserDataEvent $event)
 {
     $user = $event->getUser();
     $token = $this->tokenGenerator->generateToken();
     $this->userManager->updateConfirmationTokenUser($user, $token);
     $message = \Swift_Message::newInstance()->setCharset('UTF-8')->setSubject($this->templating->loadTemplate($this->template)->renderBlock('subject', []))->setFrom($this->from)->setTo($user->getEmail())->setBody($this->templating->loadTemplate($this->template)->renderBlock('body', ['username' => $user->getUsername(), 'request_link' => $this->router->generate('reset_password', ['token' => $token], true)]));
     $this->mailer->send($message);
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $this->handler->createUser($form->getData()->getUser());
     return true;
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $this->handler->updateCredentials($form->getData()->getUser(), $form->getData()->getNewPassword());
     return true;
 }
 /**
  * @param FormInterface $form
  * @param Request       $request
  * @param array         $options
  *
  * @return bool
  */
 public function handle(FormInterface $form, Request $request, array $options = null)
 {
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return false;
     }
     $token = $request->query->get('token');
     $user = $this->handler->getUserByConfirmationToken($token);
     $this->handler->clearConfirmationTokenUser($user);
     $this->handler->updateCredentials($user, $form->getData()->getPassword());
     return true;
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('password', 'repeated', array('first_name' => 'password', 'second_name' => 'confirm', 'type' => 'password'));
     $builder->add('Reset Password', 'submit');
     $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
         $data = $event->getData();
         if (!$data instanceof ResetPassword) {
             throw new \RuntimeException('ChangePassword instance required.');
         }
         $token = $this->request->query->get('token');
         if (!$token) {
             throw new \Exception('Incorrect Token.');
         }
         $user = $this->handler->getUserByConfirmationToken($token);
         if (!$user) {
             throw new \Exception('User not identified in our database with this token.');
         }
     });
 }
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('oldPassword', 'password', ['required' => false])->add('newPassword', 'repeated', ['required' => false, 'type' => 'password', 'first_options' => ['label' => 'New Password'], 'second_options' => ['label' => 'Confirmation']]);
     $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
         $data = $event->getData();
         if (!$data instanceof ChangePassword) {
             throw new \RuntimeException('ChangePassword instance required.');
         }
         $oldPassword = $data->getOldPassword();
         $newPassword = $data->getNewPassword();
         $form = $event->getForm();
         if (!$oldPassword || !$newPassword || count($form->getErrors(true))) {
             return;
         }
         $user = $data->getUser();
         if (!$this->handler->isPasswordValid($user, $oldPassword)) {
             $form = $event->getForm();
             $form->get('oldPassword')->addError(new FormError('Previous password is not valid.'));
             return;
         }
     });
 }