Ejemplo n.º 1
0
 public function testCustomFields()
 {
     $user = $this->userManager->createUser('*****@*****.**', 'pass');
     $user->setCustomField('field1', 'foo');
     $user->setCustomField('field2', 'bar');
     $this->userManager->insert($user);
     $storedUser = $this->userManager->getUser($user->getId());
     $this->assertEquals('foo', $storedUser->getCustomField('field1'));
     $this->assertEquals('bar', $storedUser->getCustomField('field2'));
     // Search by two custom fields.
     $foundUser = $this->userManager->findOneBy(array('customFields' => array('field1' => 'foo', 'field2' => 'bar')));
     $this->assertEquals($user, $foundUser);
     // Search by one custom field and one standard property.
     $foundUser = $this->userManager->findOneBy(array('id' => $user->getId(), 'customFields' => array('field2' => 'bar')));
     $this->assertEquals($user, $foundUser);
     // Failed search returns null.
     $foundUser = $this->userManager->findOneBy(array('customFields' => array('field1' => 'foo', 'field2' => 'does-not-exist')));
     $this->assertNull($foundUser);
 }
Ejemplo n.º 2
0
 /**
  * @param Application $app
  * @param Request $request
  * @param string $token
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
  */
 public function resetPasswordAction(Application $app, Request $request, $token)
 {
     if (!$this->isPasswordResetEnabled()) {
         throw new NotFoundHttpException('Password resetting is not enabled.');
     }
     $tokenExpired = false;
     $user = $this->userManager->findOneBy(array('confirmationToken' => $token));
     if (!$user) {
         $tokenExpired = true;
     } else {
         if ($user->isPasswordResetRequestExpired($app['user.options']['passwordReset']['tokenTTL'])) {
             $tokenExpired = true;
         }
     }
     if ($tokenExpired) {
         $app['session']->getFlashBag()->set('alert', 'Sorry, your password reset link has expired.');
         return $app->redirect($app['url_generator']->generate('user.login'));
     }
     $error = '';
     if ($request->isMethod('POST')) {
         // Validate the password
         $password = $request->request->get('password');
         if ($password != $request->request->get('confirm_password')) {
             $error = 'Passwords don\'t match.';
         } else {
             if ($error = $this->userManager->validatePasswordStrength($user, $password)) {
             } else {
                 // Set the password and log in.
                 $this->userManager->setUserPassword($user, $password);
                 $user->setConfirmationToken(null);
                 $user->setEnabled(true);
                 $this->userManager->update($user);
                 $this->userManager->loginAsUser($user);
                 $app['session']->getFlashBag()->set('alert', 'Your password has been reset and you are now signed in.');
                 return $app->redirect($app['url_generator']->generate('user.view', array('id' => $user->getId())));
             }
         }
     }
     return $app['twig']->render($this->getTemplate('reset-password'), array('layout_template' => $this->getTemplate('layout'), 'user' => $user, 'token' => $token, 'error' => $error));
 }