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


PHP UserResponseInterface::getResourceOwner方法代碼示例

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


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

示例1: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $useremail = $response->getEmail();
     // get facebook email id
     $user = $this->userManager->findUserByEmail($useremail);
     //$user = $this->userManager->findUserBy(array($this->getProperty($response) => $useremail));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         $user->setUsername($useremail);
         $user->setEmail($useremail);
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     $user = $this->userManager->findUserByEmail($useremail);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
開發者ID:krombox,項目名稱:motion,代碼行數:34,代碼來源:FOSUBUserProvider.php

示例2: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     #        $username = $response->getUsername();
     #        var_dump($username);exit;
     $username = $response->getResponse()["username"];
     var_dump($username);
     $user = $this->userManager->findUserBy(array('username' => $username));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setUsername($username);
         #    $user->setNickname($response->getNickName());
         $user->setEmail($username . '@yoursite.com');
         $user->setPassword($username);
         #    $user->setPath($response->getProfilePicture());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
開發者ID:michaelwang,項目名稱:openshop,代碼行數:35,代碼來源:Member.php

示例3: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $email = $response->getEmail();
     $nickname = $response->getRealName();
     //var_dump($email); die();
     $user = $this->userManager->findUserByUsernameOrEmail($email);
     //$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
     //when the user is registrating
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setUsername($nickname);
         $user->setEmail($email);
         $user->setPlainPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     //$user = parent::loadUserByOAuthUserResponse($response);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
開發者ID:podisto,項目名稱:openwecco,代碼行數:38,代碼來源:FOSUBUserProvider.php

示例4: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response, $email = "")
 {
     $useremail = $response->getEmail();
     if ($useremail == "") {
         $useremail = $email;
     }
     if ($useremail != "") {
         $username = $useremail;
     } else {
         $username = $response->getUsername();
     }
     /** @var User $user */
     $user = $this->userManager->findUserByUsernameOrEmail($username);
     $service = $response->getResourceOwner()->getName();
     $setterID = $service . "Id";
     $setter = 'set' . ucfirst($service);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     $getter = 'get' . ucfirst($service);
     $getter_id = $getter . 'Id';
     //when the user is registrating
     if (null === $user) {
         if ($this->userManager->findUserBy(array($setterID => $response->getUsername())) != null) {
             $user = $this->userManager->findUserBy(array($setterID => $response->getUsername()));
             return $user;
         } else {
             // create new user here
             $user = $this->userManager->createUser();
             $user->{$setter_id}($username);
             $user->{$setter_token}($response->getAccessToken());
             $user->setUsername($username);
             $user->setFullname($response->getRealName());
             if ($response->getResourceOwner()->getName() == 'facebook') {
                 $user->setPhoto('https://graph.facebook.com/' . $response->getUsername() . '/picture?type=large');
             } else {
                 $user->setPhoto($response->getProfilePicture());
             }
             $user->setPassword($username);
             $user->setEnabled(true);
             if (filter_var($response->getEmail(), FILTER_VALIDATE_EMAIL)) {
                 $user->setEmail($response->getEmail());
                 $user->setConfirmationToken(null);
             } else {
                 $user->setEmail($username);
             }
             $this->userManager->updateUser($user);
             return $user;
         }
     } else {
         $user->{$setter_id}($response->getUsername());
         $user->{$setter_token}($response->getAccessToken());
         $this->userManager->updateUser($user);
         return $user;
     }
 }
開發者ID:Alex223124,項目名稱:edela,代碼行數:58,代碼來源:FOSUBUserProvider.php

示例5: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userEmail = $response->getEmail();
     $user = $this->userManager->findUserByEmail($userEmail);
     // if null just create new user and set it properties
     if (null === $user) {
         $userData = $response->getResponse();
         $user = new User();
         $user->setUsername($userData['formattedName']);
         $user->setPlainPassword(rand(1000000, 10000000));
         //TODO:find a better option
         //TODO: add location, company name, ..
         $user->setEmail($response->getEmail());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         $this->em->flush();
         return $user;
     }
     // else update access token of existing user
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     $user->{$setter}($response->getAccessToken());
     //update access token
     return $user;
 }
開發者ID:OpenSkills,項目名稱:skillsprofile,代碼行數:28,代碼來源:MyFOSUBUserProvider.php

示例6: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $generator = new SecureRandom();
     $random = $generator->nextBytes(10);
     $data = $response->getResponse();
     $username = $response->getUsername();
     $email = $response->getEmail() ? $response->getEmail() : $username;
     $service = $response->getResourceOwner()->getName();
     $user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
     //$user = $this->userManager->findUserBy(array($service.'Id' => $username));
     //when the user is registrating
     if (null === $user) {
         $setter = 'set' . ucfirst($service);
         $setter_id = $setter . 'Id';
         $setter_token = $setter . 'AccessToken';
         // create new user here
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         $user->setUsername($email);
         $user->setEmail($email);
         $user->setPlainPassword($random);
         $user->setName($response->getRealName());
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $user = parent::loadUserByOAuthUserResponse($response);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
開發者ID:roman-movchan,項目名稱:salefactor,代碼行數:35,代碼來源:FOSUBUserProvider.php

示例7: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $serviceName = $response->getResourceOwner()->getName();
     $data = array();
     if ($serviceName == 'facebook') {
         $data = $this->getFacebookData($response);
         $user = $this->userManager->findUserBy(array($this->getProperty($response) => $data['id']));
     } else {
         if ($serviceName == 'soundcloud') {
             $data = $this->getSoundcloudData($response);
             $user = $this->userManager->findUserBy(array($this->getProperty($response) => $data['id']));
         }
     }
     $setService = 'set' . ucfirst($serviceName);
     $setServiceId = $setService . 'Id';
     $setServiceToken = $setService . 'AccessToken';
     if (null === $user) {
         $user = $this->userManager->createUser();
         if ($serviceName == 'facebook') {
             $user = $this->setFacebookData($user, $data, $setServiceId, $setServiceToken);
         } else {
             if ($serviceName == 'soundcloud') {
                 $user = $this->setSoundcloudData($user, $data, $setServiceId, $setServiceToken);
             }
         }
         $this->userManager->updateUser($user);
         return $user;
     }
     $user->{$setServiceToken}($response->getAccessToken());
     return $user;
 }
開發者ID:jraisanen,項目名稱:user-bundle,代碼行數:31,代碼來源:FOSUBUserProvider.php

示例8: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $content = $response->getResponse();
     $resourceOwner = $response->getResourceOwner();
     try {
         $user = $this->loadUserByServiceAndId($resourceOwner->getName(), $content['id']);
         return $user;
     } catch (\Exception $e) {
         $name = $response->getRealName();
         $nameArray = explode(' ', $name, 2);
         $firstName = $response->getFirstName();
         $lastName = $response->getLastName();
         if (empty($firstName) || empty($lastName)) {
             if (array_key_exists(0, $nameArray)) {
                 $firstName = ucfirst(strtolower($nameArray[0]));
             }
             if (array_key_exists(1, $nameArray)) {
                 $lastName = ucfirst(strtolower($nameArray[1]));
             }
         }
         $user = array();
         $user['firstName'] = $firstName;
         $user['lastName'] = $lastName;
         $user['username'] = $this->createUsername($response->getNickname());
         $user['mail'] = $response->getEmail();
         $this->session->set('icap.oauth.user', $user);
         $resourceOwnerArray = array('name' => $resourceOwner->getName(), 'id' => $content['id']);
         $this->session->set('icap.oauth.resource_owner', $resourceOwnerArray);
         throw $e;
     }
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:34,代碼來源:OauthUserProvider.php

示例9: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     try {
         $resourceOwnerName = $response->getResourceOwner()->getName();
         if (!isset($this->properties[$resourceOwnerName])) {
             throw new \RuntimeException(sprintf("No property defined for entity for resource owner '%s'.", $resourceOwnerName));
         }
         $username = $response->getUsername();
         if (null === ($user = $this->repository->findOneBy(array($this->properties[$resourceOwnerName] => $username)))) {
             throw new UsernameNotFoundException(sprintf("User '%s' not found.", $username));
         }
         return $user;
     } catch (UsernameNotFoundException $e) {
         $rawResponse = $response->getResponse();
         $user = new User($rawResponse['screen_name']);
         $user->setTwitterId($rawResponse['id']);
         $user->setUsername($rawResponse['screen_name']);
         $user->setTodaySinceId('');
         $user->setIsActive(true);
         $user->setCreateAt(new \DateTime());
         $user->setUpdateAt(new \DateTime());
         $this->em->persist($user);
         $this->em->flush();
         return $user;
     }
 }
開發者ID:ryota-murakami,項目名稱:daily-tweet,代碼行數:26,代碼來源:OAuthEntityUserProvider.php

示例10: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $service = $response->getResourceOwner()->getName();
     $user = $this->userManager->findUserBy(array($this->getProperty($response) => $username, 'auth_type' => $service));
     //when the user is registrating
     if (null === $user) {
         $user = $this->userManager->createUser();
         $user->setUid($username);
         $user->setAccessToken($response->getAccessToken());
         $user->setAuthType($service);
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setUsername($response->getRealName());
         $user->setUsernameCanonical($username);
         $user->setEmail($response->getEmail());
         if ($service == "facebook") {
             $user->setPicture("https://graph.facebook.com/{$username}/picture");
         } else {
             $user->setPicture($response->getProfilePicture());
         }
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $user = parent::loadUserByOAuthUserResponse($response);
     //update access token
     $user->setAccessToken($response->getAccessToken());
     return $user;
 }
開發者ID:lahiiru,項目名稱:Quota,代碼行數:35,代碼來源:FOSUBUserProvider.php

示例11: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $email = $response->getEmail();
     $service = $response->getResourceOwner()->getName();
     /** @var UserOauthAccount $connection */
     $connection = $this->em->getRepository('OjsUserBundle:UserOauthAccount')->findOneBy(['providerId' => $username, 'provider' => $service]);
     if (!$connection && !empty($email)) {
         $userByEmail = $this->userManager->findUserByEmail($email);
         if ($userByEmail) {
             $connection = new UserOauthAccount();
             $connection->setUser($userByEmail);
             $connection->setProvider($service);
             $connection->setProviderId($response->getUsername());
         }
     }
     if (!$connection || $connection->getUser() === null) {
         $message = sprintf("User not found. Please register first and then connect the account from your profile.", $username);
         throw new AccountNotLinkedException($message);
     }
     $connection->setToken($response->getAccessToken());
     $this->em->persist($connection);
     $this->em->flush();
     return $connection->getUser();
 }
開發者ID:beyzakokcan,項目名稱:ojs,代碼行數:25,代碼來源:FOSUBUserProvider.php

示例12: loadUserByOAuthUserResponse

 /**
  * @param UserResponseInterface $response
  * @return mixed
  * @throws OAuthAwareException
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $tokenLoggedUser = $this->container->get('security.token_storage')->getToken();
     $oauthServiceName = $response->getResourceOwner()->getName();
     $oauthServiceUserId = $response->getUsername();
     $oauthServiceAccessToken = $response->getAccessToken();
     $user = $this->entityManager->getRepository('AppBundle:User')->findOneBy(array($oauthServiceName . '_id' => $oauthServiceUserId));
     $setter = 'set' . ucfirst($oauthServiceName);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     if (null === $user) {
         if (null === $tokenLoggedUser) {
             throw new AccountNotLinkedException(sprintf('Not linked "%s" account could be found', $oauthServiceName));
         }
         $currentLoggedUser = $tokenLoggedUser->getUser();
         if (in_array('ROLE_ADMIN', $currentLoggedUser->getRoles())) {
             $currentLoggedUser->{$setter_id}($oauthServiceUserId);
             $currentLoggedUser->{$setter_token}($oauthServiceAccessToken);
             $this->entityManager->persist($currentLoggedUser);
             $this->entityManager->flush();
             $user = $this->entityManager->getRepository('AppBundle:User')->find($currentLoggedUser->getId());
             return $user;
         } else {
             throw new OAuthAwareException(sprintf('Only users with role "ROLE_ADMIN" can link OAuth accounts.', $oauthServiceName));
         }
     } else {
         $user->{$setter_token}($response->getAccessToken());
         $this->entityManager->persist($user);
         $this->entityManager->flush();
         return $user;
     }
 }
開發者ID:alfonsomga,項目名稱:symfony.demo.on.roids,代碼行數:37,代碼來源:UserProvider.php

示例13: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $resourceOwner = $response->getResourceOwner();
     if (!$resourceOwner instanceof FacebookResourceOwner) {
         throw new UnsupportedUserException('Only Facebook users are supported');
     }
     return $this->loadUserByData(['userId' => $response->getUsername(), 'service' => 'facebook', 'username' => $response->getNickname(), 'realname' => $response->getRealName(), 'email' => $response->getEmail(), 'picture' => $response->getProfilePicture()]);
 }
開發者ID:paza,項目名稱:HotOrNot,代碼行數:11,代碼來源:OAuthUserProvider.php

示例14: getProperty

 /**
  * Gets the property for the response.
  *
  * @param UserResponseInterface $response
  *
  * @return string
  *
  * @throws \RuntimeException
  */
 protected function getProperty(UserResponseInterface $response)
 {
     $resourceOwnerName = $response->getResourceOwner()->getName();
     if (!isset($this->properties[$resourceOwnerName])) {
         throw new \RuntimeException(sprintf("No property defined for entity for resource owner '%s'.", $resourceOwnerName));
     }
     return $this->properties[$resourceOwnerName];
 }
開發者ID:rafalwrzeszcz,項目名稱:HWIOAuthBundle,代碼行數:17,代碼來源:FOSUBUserProvider.php

示例15: findByOAuthResponse

 /**
  * @return User
  * @throws InvalidArgumentException if no user is found
  */
 public function findByOAuthResponse(UserResponseInterface $oAuthResponse)
 {
     $foundUser = $this->doctrineUserRepo->findOneBy(['oAuthProviderClass' => get_class($oAuthResponse->getResourceOwner()), 'oAuthId' => $oAuthResponse->getUsername()]);
     if (null === $foundUser) {
         throw new \InvalidArgumentException("user not found");
     }
     return $foundUser;
 }
開發者ID:lukaszmakuch,項目名稱:question-sheet-storage,代碼行數:12,代碼來源:UserRepo.php


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