當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserManagerInterface::findUserBy方法代碼示例

本文整理匯總了PHP中FOS\UserBundle\Model\UserManagerInterface::findUserBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserManagerInterface::findUserBy方法的具體用法?PHP UserManagerInterface::findUserBy怎麽用?PHP UserManagerInterface::findUserBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在FOS\UserBundle\Model\UserManagerInterface的用法示例。


在下文中一共展示了UserManagerInterface::findUserBy方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: refreshUser

 /**
  * {@inheritDoc}
  */
 public function refreshUser(SecurityUserInterface $user)
 {
     if (!$user instanceof User && !$user instanceof PropelUser) {
         throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user)));
     }
     if (null === ($reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId())))) {
         throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $user->getId()));
     }
     return $reloadedUser;
 }
開發者ID:glaisner,項目名稱:PST4---Woodstack,代碼行數:13,代碼來源:UserProvider.php

示例2: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->userManager->findUserBy(['githubId' => $response->getUsername()]);
     if ($user instanceof User) {
         return $user;
     }
     // Try to create user
     $user = $this->createUserFromResponse($response);
     return $user;
 }
開發者ID:stfalcon-studio,項目名稱:codedill,代碼行數:13,代碼來源:AuthProvider.php

示例3: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $user = $this->userManager->findUserBy(array('githubId' => $username));
     if (!$user) {
         throw new AccountNotLinkedException(sprintf('No user with github username "%s" was found.', $username));
     }
     if (!$user->getGithubToken()) {
         $user->setGithubToken($response->getAccessToken());
         $this->userManager->updateUser($user);
     }
     return $user;
 }
開發者ID:enriquesomolinos,項目名稱:packagist,代碼行數:16,代碼來源:UserProvider.php

示例4: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->userManager->findUserBy(['facebookId' => $response->getUsername()]);
     if ($user instanceof User) {
         $actionLog = (new UserActionLog())->setActionType(UserActionType::LOGIN)->setUser($user)->setCreatedAt(new \DateTime('now'));
         $em = $this->entityManager;
         $em->persist($actionLog);
         $em->flush();
         return $user;
     }
     // Try to create user
     $user = $this->createUserFromResponse($response);
     return $user;
 }
開發者ID:stfalcon-studio,項目名稱:lost-and-found,代碼行數:17,代碼來源:AuthProvider.php

示例5: connect

 /**
  * {@inheritDoc}
  */
 public function connect($user, UserResponseInterface $response)
 {
     $property = $this->getProperty($response);
     $setter = 'set' . ucfirst($property);
     if (!method_exists($user, $setter)) {
         throw new \RuntimeException(sprintf("Class '%s' should have a method '%s'.", get_class($user), $setter));
     }
     $username = $response->getUsername();
     if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) {
         $previousUser->{$setter}(null);
         $this->userManager->updateUser($previousUser);
     }
     $user->{$setter}($username);
     $this->userManager->updateUser($user);
 }
開發者ID:rafalwrzeszcz,項目名稱:HWIOAuthBundle,代碼行數:18,代碼來源:FOSUBUserProvider.php

示例6: onSecurityInteractiveLogin

 /**
  * On user login
  *
  * @param InteractiveLoginEvent $event Event
  */
 public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
 {
     /**
      * @var User $user
      */
     $user = $event->getAuthenticationToken()->getUser();
     $referralService = $this->container->get('stfalcon_event.referral.service');
     if ($this->request->cookies->has(ReferralService::REFERRAL_CODE)) {
         $referralCode = $this->request->cookies->get(ReferralService::REFERRAL_CODE);
         //check self referral code
         if ($referralService->getReferralCode($user) !== $referralCode) {
             $userReferral = $this->userManager->findUserBy(['referralCode' => $referralCode]);
             if ($userReferral) {
                 $user->setUserReferral($userReferral);
             }
             $this->userManager->updateUser($user);
         }
     }
 }
開發者ID:bolotyuh,項目名稱:fwdays,代碼行數:24,代碼來源:UserLoginListener.php

示例7: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userInfo = $this->getUserInfo($response);
     $service = $response->getResourceOwner()->getName();
     $user = $this->userManager->findUserBy(array("{$service}Id" => $userInfo['id']));
     if ($user instanceof PersonInterface) {
         $user = parent::loadUserByOAuthUserResponse($response);
         $serviceName = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
         $user->{$setter}($response->getAccessToken());
         return $user;
     }
     $userInfo = $this->checkEmail($service, $userInfo);
     $user = $this->userManager->createUser();
     $this->setUserInfo($user, $userInfo, $service);
     if ($userInfo['first_name']) {
         $user->setFirstName($userInfo['first_name']);
     }
     if ($userInfo['family_name']) {
         $user->setSurname($userInfo['family_name']);
     }
     if ($service === 'facebook') {
         $this->setFacebookData($user, $response->getResponse());
     }
     $username = Uuid::uuid4()->toString();
     if (!UsernameValidator::isUsernameValid($username)) {
         $username = UsernameValidator::getValidUsername();
     }
     $availableUsername = $this->userManager->getNextAvailableUsername($username, 10, Uuid::uuid4()->toString());
     $user->setUsername($availableUsername);
     $user->setEmail($userInfo['email']);
     $user->setPassword('');
     $user->setEnabled(true);
     $this->userManager->updateCanonicalFields($user);
     /** @var ValidatorInterface $validator */
     $validator = $this->container->get('validator');
     /** @var ConstraintViolationList $errors */
     $errors = $validator->validate($user, ['LoginCidadaoProfile']);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             if ($error->getPropertyPath() === 'email' && method_exists($error, 'getConstraint') && $error->getConstraint() instanceof UniqueEntity) {
                 throw new DuplicateEmailException($service);
             }
         }
     }
     $form = $this->formFactory->createForm();
     $form->setData($user);
     $request = $this->container->get('request');
     $eventResponse = new RedirectResponse('/');
     $event = new FormEvent($form, $request);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
     $this->userManager->updateUser($user);
     $this->dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $eventResponse));
     return $user;
 }
開發者ID:redelivre,項目名稱:login-cidadao,代碼行數:58,代碼來源:FOSUBUserProvider.php

示例8: refreshUser

 /**
  * {@inheritDoc}
  */
 public function refreshUser(UserInterface $user)
 {
     // Compatibility with FOSUserBundle < 2.0
     if (class_exists('FOS\\UserBundle\\Form\\Handler\\RegistrationFormHandler')) {
         return $this->userManager->refreshUser($user);
     }
     if (!$user instanceof User) {
         throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user)));
     }
     if (null === ($reloadedUser = $this->userManager->findUserBy(array('id' => $user->getId())))) {
         throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $user->getId()));
     }
     return $user;
 }
開發者ID:michaeljayt,項目名稱:HWIOAuthBundle,代碼行數:17,代碼來源:FOSUBUserProvider.php

示例9: refreshUser

 /**
  * {@inheritDoc}
  */
 public function refreshUser(UserInterface $user)
 {
     // Compatibility with FOSUserBundle < 2.0
     if (class_exists('FOS\\UserBundle\\Form\\Handler\\RegistrationFormHandler')) {
         return $this->userManager->refreshUser($user);
     }
     $identifier = $this->properties['identifier'];
     if (!$user instanceof User || !$this->accessor->isReadable($user, $identifier)) {
         throw new UnsupportedUserException(sprintf('Expected an instance of FOS\\UserBundle\\Model\\User, but got "%s".', get_class($user)));
     }
     $userId = $this->accessor->getValue($user, $identifier);
     if (null === ($user = $this->userManager->findUserBy(array($identifier => $userId)))) {
         throw new UsernameNotFoundException(sprintf('User with ID "%d" could not be reloaded.', $userId));
     }
     return $user;
 }
開發者ID:Aukraiser,項目名稱:YetAnotherTweetsAnalyzer,代碼行數:19,代碼來源:FOSUBUserProvider.php

示例10: findUserByFacebookId

 public function findUserByFacebookId($fbId)
 {
     return $this->FOSUserManager->findUserBy(['facebookId' => $fbId]);
 }
開發者ID:viettut,項目名稱:todo,代碼行數:4,代碼來源:LecturerManager.php

示例11: find

 /**
  * @inheritdoc
  */
 public function find($id)
 {
     return $this->FOSUserManager->findUserBy(['id' => $id]);
 }
開發者ID:viettut,項目名稱:api,代碼行數:7,代碼來源:LecturerManager.php

示例12: findUser

 /**
  * Finds a user by username.
  *
  * This method is meant to be an extension point for child classes.
  *
  * @param string $username
  *
  * @return UserInterface|null
  */
 protected function findUser($username)
 {
     return $this->userManager->findUserBy(array('apiKey' => $username));
 }
開發者ID:bogdy2p,項目名稱:oviTiut,代碼行數:13,代碼來源:UserProvider.php


注:本文中的FOS\UserBundle\Model\UserManagerInterface::findUserBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。