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


PHP UserResponseInterface::getUsername方法代码示例

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


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

示例1: loadUserByOAuthUserResponse

 /**
  * @param UserResponseInterface $response
  * @return User
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     /** @var User $user */
     $user = $this->userManager->findUserBy(['slackUserName' => $response->getUsername()]);
     if ($user === null) {
         $user = $this->userManager->createUser();
         $user->setSlackUserName($username);
         $user->setSlackAccessToken($response->getAccessToken());
         $user->setUsername($response->getNickname());
         $user->setEmail($response->getEmail());
         $user->setRealName($response->getRealName());
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         $token = new Token($user);
         $this->tokenRepository->persist($token);
         $user->addToken($token);
         $this->userManager->updateUser($user);
         return $user;
     }
     $user = parent::loadUserByOAuthUserResponse($response);
     $user->setSlackAccessToken($response->getAccessToken());
     $user->setRealName($response->getRealName());
     $token = new Token($user);
     $this->tokenRepository->persist($token);
     $user->addToken($token);
     $this->userManager->updateUser($user);
     return $user;
 }
开发者ID:jordi12100,项目名称:ExpertTools,代码行数:34,代码来源:UserProvider.php

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

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

示例4: createUserFromResponse

 /**
  * Create user from response
  *
  * @param UserResponseInterface $response
  *
  * @return User
  */
 private function createUserFromResponse(UserResponseInterface $response)
 {
     /** @var User $user User */
     $user = $this->userManager->createUser();
     $user->setUsername($response->getUsername())->setFullName($response->getRealName())->setEmail($response->getEmail())->setEnabled(true)->setPlainPassword(uniqid())->setFacebookId($response->getUsername())->setFacebookAccessToken($response->getAccessToken());
     $this->eventDispatcher->dispatch(AppEvents::FACEBOOK_USER_CONNECTED, new FacebookUserConnectedEvent($user));
     $this->userManager->updateUser($user);
     return $user;
 }
开发者ID:stfalcon-studio,项目名称:lost-and-found,代码行数:16,代码来源:AuthProvider.php

示例5: __construct

 public function __construct(UserResponseInterface $response)
 {
     parent::__construct($response->getUsername());
     $this->data = array('provider' => $response->getResourceOwner()->getName(), 'providerId' => $response->getUsername());
     $vars = array('nickname', 'realname', 'email', 'profilePicture', 'accessToken', 'refreshToken', 'tokenSecret', 'expiresIn');
     foreach ($vars as $v) {
         $fct = 'get' . ucfirst($v);
         $this->data[$v] = $response->{$fct}();
     }
 }
开发者ID:aubelj,项目名称:srcLocal,代码行数:10,代码来源:OAuthUser.php

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

示例7: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     //Data from Facebook response
     $user_details = $response->getResponse();
     $facebook_Id = $response->getUsername();
     /* An ID like: 112259658235204980084 */
     $email = $user_details['email'];
     $first_name = $user_details['first_name'];
     $last_name = $user_details['last_name'];
     $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('CvProUserBundle:User', 'u')->where('u.facebookId = :gid')->setParameter('gid', $facebook_Id)->setMaxResults(1);
     $result = $qb->getQuery()->getResult();
     //add to database if doesn't exist
     if (!count($result)) {
         $user = new User();
         $user->setUsername($facebook_Id);
         $user->setFirstName($first_name);
         $user->setLastName($last_name);
         // $user->setRealname($realname);
         // $user->setNickname($nickname);
         $user->setEmail($email);
         $user->setFacebookId($facebook_Id);
         //$user->setRoles('ROLE_USER');
         //Set some wild random pass since its irrelevant, this is facebook 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:medy36,项目名称:OauthSymfony,代码行数:48,代码来源:OAuthProvider.php

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

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

示例10: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getNickname();
     $twitterId = $response->getUsername();
     $accessToken = $response->getAccessToken();
     $secretToken = $response->getTokenSecret();
     $user = $this->userManager->findUserByUsername($username);
     //when the user is registrating
     if (is_null($user)) {
         // create new user here
         $user = $this->userManager->createUser();
         $user->setUsername($username);
         $user->setAccessToken($accessToken);
         $user->setTwitterId($twitterId);
         $user->setSecretToken($secretToken);
         //I have set all requested data with the user's username
         //modify here with relevant data
         $user->setEmail($username);
         $user->setPlainPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $user->setAccessToken($accessToken);
     $user->setSecretToken($secretToken);
     return $user;
 }
开发者ID:josenava,项目名称:showHashtag,代码行数:31,代码来源:FOSUBUserProvider.php

示例11: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $socialID = $response->getUsername();
     $user = $this->userManager->findUserBy(array($this->getProperty($response) => $socialID));
     $email = $response->getEmail();
     //check if the user already has the corresponding social account
     if (null === $user) {
         //check if the user has a normal account
         $user = $this->userManager->findUserByEmail($email);
         if (null === $user || !$user instanceof UserInterface) {
             //if the user does not have a normal account, set it up:
             $user = $this->userManager->createUser();
             $user->setEmail($email);
             $user->setPlainPassword(md5(uniqid()));
             $user->setEnabled(true);
         }
         //then set its corresponding social id
         $service = $response->getResourceOwner()->getName();
         switch ($service) {
             case 'google':
                 $user->setGoogleID($socialID);
                 break;
             case 'facebook':
                 $user->setFacebookID($socialID);
                 break;
         }
         $this->userManager->updateUser($user);
     } else {
         //and then login the user
         $checker = new UserChecker();
         $checker->checkPreAuth($user);
     }
     return $user;
 }
开发者ID:armandomeeuwenoord,项目名称:icup,代码行数:37,代码来源:OAuthUserProvider.php

示例12: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $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';
         // create new user here
         /** @var User $user */
         $user = $this->userManager->createUser();
         $user->{$setter_id}($username);
         $user->setUsername($response->getNickname());
         $user->setEmail($response->getEmail());
         $user->setPassword('');
         $user->setEnabled(true);
         $socialData = $response->getResponse();
         if ($service == 'vkontakte') {
             $socialData = $socialData['response'][0];
         }
         $user->setFirstname($socialData['first_name']);
         $user->setLastname($socialData['last_name']);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     $user = parent::loadUserByOAuthUserResponse($response);
     return $user;
 }
开发者ID:kipelovets,项目名称:kipelovets,代码行数:33,代码来源:FOSUBUserProvider.php

示例13: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $userId = $response->getUsername();
     $user = $this->userManager->findUserBy(array($this->getProperty($response) => $userId));
     $email = $response->getEmail();
     $username = $response->getNickname() ?: $response->getRealName();
     if (null === $user) {
         $user = $this->userManager->findUserByUsernameAndEmail($username, $email);
         if (null === $user || !$user instanceof UserInterface) {
             $user = $this->userManager->createUser();
             $username = str_replace(' ', '', $username);
             $user->setUsername($username);
             $user->setEmail($email);
             $user->setPassword('');
             $user->setEnabled(true);
             $user->setOAuthService($response->getResourceOwner()->getName());
             $user->setOAuthId($userId);
             $user->setOAuthAccessToken($response->getAccessToken());
             $this->userManager->updateUser($user);
         } else {
             throw new AuthenticationException('Username or email has been already used.');
         }
     } else {
         $checker = new UserChecker();
         $checker->checkPreAuth($user);
     }
     return $user;
 }
开发者ID:robertorodriguezgarcia,项目名称:qcs,代码行数:31,代码来源:OAuthUserProvider.php

示例14: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $user = $this->repository->findOneBy(array($this->getProperty($response) => $username));
     // Register user
     if (null === $user && $username) {
         $service = $response->getResourceOwner()->getName();
         $idField = $service . 'Id';
         $tokenField = $service . 'AccessToken';
         $class = $this->repository->getClassName();
         $user = new $class();
         $this->accessor->setValue($user, $idField, $username);
         $this->accessor->setValue($user, $tokenField, $response->getAccessToken());
         $user->setUsername($username);
         $user->setEmail($username);
         $user->setIsActive(true);
         $this->em->persist($user);
         $this->em->flush();
         return $user;
     } elseif (!$username) {
         throw new \InvalidArgumentException('Username missing');
     } else {
         return $user;
     }
 }
开发者ID:builtwithheart,项目名称:bookmarker,代码行数:28,代码来源:OauthUserProvider.php

示例15: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $realName = $response->getRealName();
     /** @var User $user */
     $user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
     if (null === $user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setterId = $setter . 'Id';
         $setterToken = $setter . 'AccessToken';
         $user = $this->userManager->createUser();
         $user->{$setterId}($username);
         $user->{$setterToken}($response->getAccessToken());
         $username = sprintf('%s_%s', $service, $username);
         $user->setUsername($username);
         $user->setRealName($realName);
         $user->setEmail($username);
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     $user = parent::loadUserByOAuthUserResponse($response);
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
开发者ID:orkestro,项目名称:orkestro,代码行数:29,代码来源:FOSUBUserProvider.php


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