/**
  * Creates a user by the new user entity
  *
  * @param User $user
  *
  * @return SimpleUserOverview
  */
 public static function fromAggregateRootDetails(User $user)
 {
     $credentials = $user->getCredentials();
     $identifier = $user->getId();
     $profileData = $user->getSimpleProfile();
     return new self($identifier, $credentials->getUsername(), $profileData->getEmail(), $profileData->getLocale());
 }
 public function testChangePassword()
 {
     $serviceMock = $this->getMock(ApiKeyFactoryInterface::class);
     $serviceMock->expects($this->any())->method('generateKeyCode')->will($this->returnValue(new ApiKey('api key')));
     $this->user->authenticateToken(new AuthDTO('Ma27', 'test-password'), $serviceMock);
     $this->user->changePassword(new ChangePasswordDTO('test-password', '123456'));
     $this->assertTrue($this->user->getCredentials()->getPassword()->compare('123456'));
 }
 /**
  * {@inheritdoc}
  */
 public function calculateSortPriority(User $perspective)
 {
     $points = 0;
     if ($this->isMarked($perspective->getId())) {
         $points += self::HIGH_SORT_CRITERION;
     }
     if ($perspective->follows($this->author->getCredentials()->getUsername())) {
         $points += self::HIGH_SORT_CRITERION;
     }
     if ($this->isShortlyWritten()) {
         $points += self::SIMPLE_SORT_CRITERION;
     }
     if ($this->isCurrent()) {
         $points += self::NORMAL_SORT_CRITERION;
     }
     return $points;
 }
 protected function assertSameUser(User $user1, UserInterface $user2)
 {
     foreach ([$user1->getCredentials()->getUsername() => $user2->getUsername(), $user1->getCredentials()->getPassword()->getHash() => $user2->getPassword()] as $expected => $actual) {
         $this->assertSame($expected, $actual);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function findUsersWithMostFollowers($maxQueryResultLength = 5, User $exclude = null)
 {
     $qb = $this->getEntityManager()->createQueryBuilder();
     $limit = (int) $maxQueryResultLength;
     $qb->select('user', 'COUNT(follower) AS HIDDEN followerCount')->from('SEN_User:User', 'user')->leftJoin('SEN_User:User', 'follower', Join::WITH, $qb->expr()->isMemberOf('user', 'follower.following'))->groupBy('followerCount')->orderBy('followerCount', 'DESC')->setMaxResults($limit);
     if (null !== $exclude) {
         $qb->where($qb->expr()->neq('user.credentials.username', ':excludeUsername'))->setParameter(':excludeUsername', $exclude->getCredentials()->getUsername());
     }
     return $qb->getQuery()->getResult();
 }
 /**
  * Creates a security user from the actual symfony user
  *
  * @param User $user
  *
  * @return SecurityUser
  */
 private function toSecurityUser(User $user)
 {
     return new SecurityUser($user->getCredentials()->getUsername(), $user->getCredentials()->getPassword()->getHash(), $this->toSecurityRole($user->getRoles()), $user->getSimpleProfile()->isLocked());
 }
Esempio n. 7
0
 /**
  * Searches for follower relations recursively
  *
  * @param User $target
  * @param integer $offset
  * @param User[] $foundSteps
  * @param integer $limit
  *
  * @return User[]
  *
  * @throws \OverflowException If the maximum search offset has reached
  */
 public function findRelationBetweenUsers(User $target, $offset = 0, array $foundSteps = [], $limit = 5)
 {
     $message = 'Maximum recursions were reached!';
     // too many loops, abort
     if ((int) $limit === $offset) {
         throw new \OverflowException($message);
     }
     foreach ($foundSteps as $user) {
         if ($user->getId() === $this->getId()) {
             throw new \OverflowException($message);
         }
     }
     $foundSteps[] = $this;
     // relation graph build process completed
     if ($this->follows($target->getCredentials()->getUsername())) {
         return $foundSteps;
     }
     // continue search
     $offset++;
     foreach ($this->getFollowing() as $followedByCurrent) {
         try {
             $result = $followedByCurrent->findRelationBetweenUsers($target, $offset, $foundSteps, $limit);
             return $result;
         } catch (\OverflowException $ex) {
             // try next following
             continue;
         }
     }
     // if no the searcher was unable to generate a proper result,
     // the overflow exception will be thrown
     throw new \OverflowException($message);
 }