Наследование: extends Sulu\Component\Persistence\Repository\ORM\EntityRepository, implements Sulu\Component\Security\Authentication\UserRepositoryInterface, use trait Sulu\Component\Persistence\Repository\ORM\OrderByTrait
Пример #1
1
 /**
  * resolves user id to user data.
  *
  * @param int $id id to resolve
  *
  * @return User
  */
 public function resolveUserFunction($id)
 {
     if ($this->cache->contains($id)) {
         return $this->cache->fetch($id);
     }
     $user = $this->userRepository->findUserById($id);
     if ($user === null) {
         return;
     }
     $this->cache->save($id, $user);
     return $user;
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Form $form, $webSpaceKey, array $options = [])
 {
     $data = $form->getData();
     $user = $this->userRepository->findOneBy(['confirmationKey' => $data['token']]);
     $user->setConfirmationKey(null);
     if ($options[Configuration::ACTIVATE_USER]) {
         if ($user instanceof BaseUser) {
             $user->setEnabled(true);
         }
     }
     $this->entityManager->persist($user);
     $this->entityManager->flush();
     return $user;
 }
Пример #3
0
 /**
  * resolves user id to user data.
  *
  * @param int $userId id to resolve
  *
  * @return Contact
  */
 public function resolveUserFunction($userId)
 {
     if (!$this->cache->contains($userId)) {
         $user = $this->userRepository->findUserById($userId);
         if ($user === null) {
             return;
         }
         $this->cache->save($userId, $user->getContact());
     }
     return $this->cache->fetch($userId);
 }
 /**
  * @return string a unique token
  */
 protected function getUniqueToken()
 {
     $token = $this->tokenGenerator->generateToken();
     try {
         $user = $this->userRepository->findUserByToken($token);
         if (!$user) {
             return $token;
         }
     } catch (NoResultException $ex) {
         return $token;
     }
     return $this->getUniqueToken();
 }
Пример #5
0
 public function testResolveUserFunction()
 {
     $user1 = new User();
     $contact1 = new Contact();
     $contact1->setFirstName('Hikaru');
     $contact1->setLastName('Sulu');
     $user1->setContact($contact1);
     $user2 = new User();
     $contact2 = new Contact();
     $contact2->setFirstName('John');
     $contact2->setLastName('Cho');
     $user2->setContact($contact2);
     $this->userRepository->expects($this->exactly(2))->method('findUserById')->will($this->returnValueMap([[1, $user1], [2, $user2]]));
     $contact = $this->extension->resolveUserFunction(1);
     $this->assertEquals('Hikaru Sulu', $contact->getFullName());
     $contact = $this->extension->resolveUserFunction(2);
     $this->assertEquals('John Cho', $contact->getFullName());
 }
 /**
  * @return string a unique token
  */
 protected function getUniqueToken()
 {
     $token = $this->tokenGenerator->generateToken();
     $user = $this->userRepository->findOneBy(['confirmationKey' => $token]);
     if (!$user) {
         return $token;
     }
     return $this->getUniqueToken();
 }
 /**
  * {@inheritdoc}
  */
 public function handle(Form $form, $webSpaceKey, array $options = [])
 {
     $data = $form->getData();
     try {
         $user = $this->userRepository->findUserByToken($data['token']);
     } catch (NoResultException $e) {
         return;
     }
     if ($user instanceof BaseUser) {
         $this->setPasswordAndSalt($form, $user);
         $user->setPasswordResetTokenExpiresAt(null);
         $user->setPasswordResetToken(null);
         if ($options[Configuration::ACTIVATE_USER]) {
             $user->setEnabled(true);
         }
         $this->entityManager->persist($user);
         $this->entityManager->flush();
     }
     return $user;
 }