/** * @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.'); } }); }