Ejemplo n.º 1
0
 public function testMigrateUp()
 {
     $userId = 1;
     $username = '******';
     $isEnabled = true;
     $confirmationToken = 'toke';
     $timePasswordResetRequested = null;
     $this->insertUserIntoV1($userId, $username, $isEnabled, $confirmationToken, $timePasswordResetRequested);
     // echo implode(";\n", $this->migrator->sqlUp());
     $this->migrator->up();
     $user = $this->userManager->getUser($userId);
     $this->assertEquals($username, $user->getUsername());
     $this->assertEquals($isEnabled, $user->isEnabled());
     $this->assertEquals($confirmationToken, $user->getConfirmationToken());
     $this->assertEquals($timePasswordResetRequested, $user->getTimePasswordResetRequested());
 }
Ejemplo n.º 2
0
 /**
  * Edit user action.
  *
  * @param Application $app
  * @param Request $request
  * @param int $id
  * @return Response
  * @throws NotFoundHttpException if no user is found with that ID.
  */
 public function editAction(Application $app, Request $request, $id)
 {
     $errors = array();
     $user = $this->userManager->getUser($id);
     if (!$user) {
         throw new NotFoundHttpException('No user was found with that ID.');
     }
     if ($request->isMethod('POST')) {
         $user->setName($request->request->get('name'));
         $user->setEmail($request->request->get('email'));
         if ($request->request->get('password')) {
             if ($request->request->get('password') != $request->request->get('confirm_password')) {
                 $errors['password'] = '******'t match.';
             } else {
                 $this->userManager->setUserPassword($user, $request->request->get('password'));
             }
         }
         if ($app['security']->isGranted('ROLE_ADMIN') && $request->request->has('roles')) {
             $user->setRoles($request->request->get('roles'));
         }
         $errors += $this->userManager->validate($user);
         if (empty($errors)) {
             $this->userManager->update($user);
             $msg = 'Saved account information.' . ($request->request->get('password') ? ' Changed password.' : '');
             $app['session']->getFlashBag()->set('alert', $msg);
         }
     }
     return $app['twig']->render($this->editTemplate, array('layout_template' => $this->layoutTemplate, 'error' => implode("\n", $errors), 'user' => $user, 'available_roles' => array('ROLE_USER', 'ROLE_ADMIN'), 'image_url' => $this->getGravatarUrl($user->getEmail())));
 }
Ejemplo n.º 3
0
 public function testAfterUpdateEvents()
 {
     $this->dispatcher->addListener(UserEvents::AFTER_UPDATE, function (UserEvent $event) {
         $event->getUser()->setCustomField('foo', 'bar');
     });
     $user = $this->userManager->createUser('*****@*****.**', 'password');
     $this->userManager->insert($user);
     // After update, the custom field set by the listener is available on the existing user instance.
     $this->assertFalse($user->hasCustomField('foo'));
     $this->userManager->update($user);
     $this->assertEquals('bar', $user->getCustomField('foo'));
     // The user was NOT stored with the custom field (because we set it AFTER update).
     // We'd have to save it again from within the after listener for it to be stored.
     $this->userManager->clearIdentityMap();
     // Clear the cache to force a fresh lookup from the database.
     $storedUser = $this->userManager->getUser($user->getId());
     $this->assertFalse($storedUser->hasCustomField('foo'));
 }