public function load(ObjectManager $manager)
 {
     for ($i = 1; $i <= 10; $i++) {
         $email = sprintf("*****@*****.**", $i);
         $user = new DiamanteUser($email, 'Test', 'User');
         $apiUser = new ApiUser($email, UserServiceImpl::generateRandomSequence(20), UserServiceImpl::generateRandomSequence(20));
         $apiUser->activate($apiUser->getHash());
         $user->setApiUser($apiUser);
         $user->setDeleted(false);
         $manager->persist($user);
     }
     $manager->flush();
 }
 /**
  * Updates DB Schema.
  * @throws \Exception if there are no changes in entities
  */
 protected function updateDbSchema()
 {
     /**
      * @var $em \Doctrine\ORM\EntityManager
      */
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $event = $em->getEventManager();
     $sm = $em->getConnection()->getSchemaManager();
     $allMetadata = $em->getMetadataFactory()->getAllMetadata();
     $schemaTool = new SchemaTool($em);
     $entitiesMetadata = array($em->getClassMetadata(ApiUser::getClassName()), $em->getClassMetadata(DiamanteUser::getClassName()));
     $event->disableListeners();
     $currentSchema = $sm->createSchema();
     $schemaFromMetadata = $schemaTool->getSchemaFromMetadata($allMetadata);
     $entitiesSchema = $schemaTool->getSchemaFromMetadata($entitiesMetadata);
     $entitiesTables = $entitiesSchema->getTables();
     $entitiesTableName = array_keys($entitiesTables);
     $currentDiamanteSchema = $this->getTargetSchema($currentSchema, $entitiesTableName);
     $diamanteSchemaFromMetadata = $this->getTargetSchema($schemaFromMetadata, $entitiesTableName);
     $comparator = new Comparator();
     $diff = $comparator->compare($currentDiamanteSchema, $diamanteSchemaFromMetadata);
     $toUpdate = $diff->toSql($em->getConnection()->getDatabasePlatform());
     if (empty($toUpdate)) {
         throw new \Exception('No new updates found. Diamante Api Bundle is up to date!');
     }
     $conn = $em->getConnection();
     foreach ($toUpdate as $sql) {
         $conn->executeQuery($sql);
     }
 }
 /**
  * @test
  */
 public function handleReturnToken()
 {
     $token = new WsseToken();
     $token->setUser('admin');
     $token->setAttribute('digest', 'admin');
     $token->setAttribute('nonce', 'admin');
     $token->setAttribute('created', '2010-12-12 20:00:00');
     $this->tokenMock->expects($this->atLeastOnce())->method('getUser')->will($this->returnValue($this->userMock));
     $this->userMock->expects($this->once())->method('isActive')->will($this->returnValue(true));
     $this->authenticationManager->expects($this->once())->method('authenticate')->with($token)->will($this->returnValue($this->tokenMock));
     /** @noinspection PhpUndefinedMethodInspection */
     $this->securityContext->expects($this->once())->method('setToken')->with($this->tokenMock);
     $this->request->headers->add(array('X-WSSE' => 'UsernameToken Username="******", PasswordDigest="admin", Nonce="admin", Created="2010-12-12 20:00:00"'));
     $this->wsseListener->handle($this->responseEvent);
 }
 /**
  * @param ApiUser $apiUser
  * @return DiamanteUser
  */
 private function loadDiamanteUser(ApiUser $apiUser)
 {
     $diamanteUser = $this->diamanteUserRepository->findUserByEmail($apiUser->getEmail());
     if (is_null($diamanteUser)) {
         throw new \RuntimeException('User loading failed, user not found.');
     }
     return $diamanteUser;
 }
 /**
  * @param \Diamante\UserBundle\Api\Command\CreateDiamanteUserCommand $command
  *
  * @return int
  */
 public function createDiamanteUser(CreateDiamanteUserCommand $command)
 {
     $user = $this->diamanteUserRepository->findUserByEmail($command->email);
     if (!is_null($user)) {
         if (true === $user->isDeleted()) {
             $this->restoreUser($user);
             return $user->getId();
         } else {
             throw new DiamanteUserExistsException('An account with this email address already exists');
         }
     }
     $user = $this->factory->create($command->email, $command->firstName, $command->lastName);
     $apiUser = new ApiUserEntity($command->email, static::generateRandomSequence(16), static::generateRandomSequence(64), $user);
     $apiUser->generateHash();
     $user->setDeleted(false);
     $user->setApiUser($apiUser);
     $apiUser->setDiamanteUser($user);
     $this->eventDispatcher->dispatch('user.notification', new UserEvent('created', $user));
     $this->diamanteUserRepository->store($user);
     return $user->getId();
 }
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage Given hash is invalid and password can not be reset.
  */
 public function testChangePasswordWhenTimeIsExpired()
 {
     $newPassword = '******';
     $apiUser = new ApiUser('username', 'password');
     $apiUser->changePassword($newPassword);
 }
 /**
  * @param OroUser|ApiUser|int $user
  * @return \Diamante\UserBundle\Entity\DiamanteUser|\Oro\Bundle\UserBundle\Entity\User
  */
 private function getUserDependingOnType($user)
 {
     if ($user instanceof OroUser) {
         return $user;
     }
     if ($user instanceof ApiUser) {
         $userId = $this->userService->verifyDiamanteUserExists($user->getEmail());
         $user = empty($userId) ? $user : new User($userId, User::TYPE_DIAMANTE);
     }
     $result = $this->userService->getByUser($user);
     return $result;
 }