当前位置: 首页>>代码示例>>PHP>>正文


PHP UserResponseInterface::getProfilePicture方法代码示例

本文整理汇总了PHP中HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface::getProfilePicture方法的典型用法代码示例。如果您正苦于以下问题:PHP UserResponseInterface::getProfilePicture方法的具体用法?PHP UserResponseInterface::getProfilePicture怎么用?PHP UserResponseInterface::getProfilePicture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface的用法示例。


在下文中一共展示了UserResponseInterface::getProfilePicture方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $google_id = $response->getUsername();
     $email = $response->getEmail();
     $nickname = $response->getNickname();
     $realname = $response->getRealName();
     $avatar = $response->getProfilePicture();
     $this->session->set('email', $email);
     $this->session->set('nickname', $nickname);
     $this->session->set('realname', $realname);
     $this->session->set('avatar', $avatar);
     $qb = $this->doctrine->getManager()->createQueryBuilder();
     $qb->select('u')->from('BookBundle:User', 'u')->where('u.googleId = :gid')->setParameter('gid', $google_id)->setMaxResults(1);
     $result = $qb->getQuery()->getResult();
     if (!count($result)) {
         $user = new User();
         $user->setUsername($google_id);
         $user->setRealname($realname);
         $user->setNickname($nickname);
         $user->setEmail($email);
         $user->setGoogleId($google_id);
         $user->setLocked(false);
         $factory = $this->container->get('security.encoder_factory');
         $encoder = $factory->getEncoder($user);
         $password = $encoder->encodePassword(md5(uniqid(), $user->getSalt()));
         $user->setPassword($password);
         $em = $this->doctrine->getManager();
         $em->persist($user);
         $em->flush();
     } else {
         $user = $result[0];
     }
     $this->session->set('id', $user->getId());
     return $this->loadUserByUsername($response->getUsername());
 }
开发者ID:bajke992,项目名称:book-app,代码行数:35,代码来源:OAuthProvider.php

示例2: 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

示例3: 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

示例4: loadUserByOAuthUserResponse

    public function loadUserByOAuthUserResponse(UserResponseInterface $response)
    {
        //Data from Google response
        $social_id = $response->getUsername(); /* An ID like: 112259658235204980084 */
        $email = $response->getEmail();
        $nickname = $response->getNickname();
        $realname = $response->getRealName();
        $avatar = $response->getProfilePicture();

        //set data in session
        $this->session->set('email', $email);
        $this->session->set('nickname', $nickname);
        $this->session->set('realname', $realname);
        $this->session->set('avatar', $avatar);

        //Check if this Google user already exists in our app DB
        $qb = $this->doctrine->getManager()->createQueryBuilder();
        $qb->select('u')
            ->from('BloggerBlogBundle:User', 'u')
            ->where('u.socialId = :sid')
            ->setParameter('sid', $social_id)
            ->setMaxResults(1);
        $result = $qb->getQuery()->getResult();

        //add to database if doesn't exists
        if (!count($result)) {
            $user = new User();
            $user->setUsername($social_id);
            $user->setRealname($realname);
            $user->setNickname($nickname);
            $user->setEmail($email);
            $user->setSocialId($social_id);
            //$user->setRoles('ROLE_USER');

            //Set some wild random pass since its irrelevant, this is Google login
            $factory = $this->container->get('security.encoder_factory');
            $encoder = $factory->getEncoder($user);
            $password = $encoder->encodePassword(md5(uniqid()), $user->getSalt());
            $user->setPassword($password);

            $em = $this->doctrine->getManager();
            $em->persist($user);
            $em->flush();
        } else {
            $user = $result[0]; /* return User */
        }

        //set id
        $this->session->set('id', $user->getId());

        return $this->loadUserByUsername($response->getUsername());
    }
开发者ID:artemzakholodilo,项目名称:blog,代码行数:52,代码来源:OAuthProvider.php

示例5: updateUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 protected function updateUserByOAuthUserResponse(UserInterface $user, UserResponseInterface $response)
 {
     /** @var UserOAuthInterface $oauth */
     $oauth = $this->oauthFactory->createNew();
     $oauth->setIdentifier($response->getUsername());
     $oauth->setProvider($response->getResourceOwner()->getName());
     $oauth->setAccessToken($response->getAccessToken());
     $oauth->setProfilePicture($response->getProfilePicture());
     /* @var DoSUserInterface $user */
     $user->addOAuthAccount($oauth);
     $this->userManager->persist($user);
     $this->userManager->flush();
     return $user;
 }
开发者ID:liverbool,项目名称:dos-user-bundle,代码行数:17,代码来源:UserProvider.php

示例6: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $uri = $this->request->getUri();
     $isFacebook = false;
     $isGoogle = false;
     $isLive = false;
     $isTwitter = false;
     if (strpos($uri, '/login_google') !== false) {
         $isGoogle = true;
     }
     if (strpos($uri, '/login_facebook') !== false) {
         $isFacebook = true;
     }
     if (strpos($uri, '/login_live') !== false) {
         $isLive = true;
     }
     if (strpos($uri, '/login_twitter') !== false) {
         $isTwitter = true;
     }
     if ($isGoogle === false && $isFacebook === false && $isLive === false && $isTwitter === false) {
         throw new \Exception("Invalid social network login attempt");
     }
     $social = "";
     if ($isGoogle) {
         $social = "google";
     }
     if ($isFacebook) {
         $social = "facebook";
     }
     if ($isLive) {
         $social = "live";
     }
     if ($isTwitter) {
         $social = "twitter";
     }
     //check to see if the user is logged in and if she is logged in with the same social network
     $isLoggedInAlready = $this->session->has('user');
     $isLoggedInAlreadyId = $this->session->get('user')['id'];
     if ($isLoggedInAlready && $this->session->get('user')['social'] == $social) {
         return $this->loadUserByUsername($isLoggedInAlreadyId);
     }
     $social_id = $response->getUsername();
     $nickname = $response->getNickname();
     $realName = $response->getRealName();
     $email = $response->getEmail();
     $avatar = $response->getProfilePicture();
     //set data in session. upon logging out we just erase the whole array.
     $sessionData = array();
     $sessionData['social_id'] = $social_id;
     $sessionData['nickname'] = $nickname;
     $sessionData['realName'] = $realName;
     $sessionData['email'] = $email;
     $sessionData['avatar'] = $avatar;
     $sessionData['social'] = $social;
     $user = null;
     if ($isLoggedInAlready) {
         $user = $this->doctrine->getRepository('CodeMe\\TheBundle\\Entity\\User')->findOneById($isLoggedInAlreadyId);
     } else {
         if ($isFacebook) {
             $user = $this->doctrine->getRepository('CodeMe\\TheBundle\\Entity\\User')->findOneByFid($social_id);
         } else {
             if ($isGoogle) {
                 $user = $this->doctrine->getRepository('CodeMe\\TheBundle\\Entity\\User')->findOneByGid($social_id);
             } else {
                 if ($isLive) {
                     $user = $this->doctrine->getRepository('CodeMe\\TheBundle\\Entity\\User')->findOneByLid($social_id);
                 } else {
                     if ($isTwitter) {
                         $user = $this->doctrine->getRepository('CodeMe\\TheBundle\\Entity\\User')->findOneByTid($social_id);
                     }
                 }
             }
         }
     }
     if ($user == null) {
         $user = new User();
         //change these only the user hasn't been registered before.
         $user->setNickname($nickname);
         $user->setRealname($realName);
         $user->setAvatar($avatar);
     }
     if ($isFacebook) {
         $user->setFid($social_id);
     } else {
         if ($isGoogle) {
             $user->setGid($social_id);
         } else {
             if ($isLive) {
                 $user->setLid($social_id);
             } else {
                 if ($isTwitter) {
                     $user->setTid($social_id);
                 }
             }
         }
     }
     $user->setLastLogin(new \DateTime('now'));
     $user->setSocial($social);
     // SET E-MAIL
     //if all emails are empty, set the first one to this one.
//.........这里部分代码省略.........
开发者ID:Turists,项目名称:rss-reader,代码行数:101,代码来源:Provider.php

示例7: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $sessionArr = $this->session->all();
     $resourceOwnerName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($resourceOwnerName);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     if (!isset($this->properties[$resourceOwnerName])) {
         throw new \RuntimeException(sprintf("No property defined for entity for resource owner '%s'.", $resourceOwnerName));
     }
     $username = $response->getUsername();
     if (isset($sessionArr['_security_secured_area'])) {
         //when user already logged and connect with other social network
         $instance = unserialize($sessionArr['_security_secured_area']);
         $user = $this->repository->findOneById($instance->getUser()->getId());
         if (!$user instanceof Actor) {
             throw new \RuntimeException("_security_secured_area key exist but any user have been stored ");
         }
         $user->{$setter_id}($username);
         $user->{$setter_token}($response->getAccessToken());
         $this->em->flush();
         return $user;
     } else {
         //when user not logged and connect with other social network
         $user = $this->repository->findOneBy(array($this->properties[$resourceOwnerName] => $username));
         if (null === $user && $resourceOwnerName != 'twitter') {
             $user = $this->repository->findOneBy(array('email' => $response->getEmail()));
         }
         //when the user is registrating
         if (null === $user) {
             // create new user here
             $user = new Actor();
             $user->{$setter_id}($username);
             $user->{$setter_token}($response->getAccessToken());
             //Encode pass
             $encoder = $this->encoderFactory->getEncoder($user);
             $password = $encoder->encodePassword($username, $user->getSalt());
             $user->setPassword($password);
             //Add ROLE
             $role = $this->em->getRepository('CoreBundle:Role')->findOneBy(array('role' => 'ROLE_USER'));
             $user->addRole($role);
             //I have set all requested data with the user's username
             //modify here with relevant data
             if (isset($oauthData['name'])) {
                 $user->setName($oauthData['name']);
             } else {
                 $user->setName($username);
             }
             $user->setUsername($username);
             if ($resourceOwnerName == 'twitter') {
                 $user->setEmail($username);
             } else {
                 $user->setEmail($response->getEmail());
             }
             $user->setIsActive(true);
             $this->em->persist($user);
             $this->em->flush();
         }
         //we need response data to update or fill: username, name, profile image
         $this->updateOAuthData($user, array('owner' => $resourceOwnerName, 'id' => $username, 'name' => $response->getRealName(), 'profileImage' => $response->getProfilePicture()));
         return $user;
     }
     //        return $user;
 }
开发者ID:sebardo,项目名称:core,代码行数:67,代码来源:OAuthUserProvider.php

示例8: loadUserByOAuthUserResponse

 /**
  * {@inheritDoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     return new MyECPUser($response->getUsername(), $response->getNickname(), $response->getEmail(), "https://my.ecp.fr" . $response->getProfilePicture(), $response->getRealName());
 }
开发者ID:pdesgarets,项目名称:myecp-sf2-consumer,代码行数:7,代码来源:MyECPProvider.php


注:本文中的HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface::getProfilePicture方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。