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


PHP UserResponseInterface::getEmail方法代码示例

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


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

示例1: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $data = $response->getResponse();
     $username = $response->getUsername();
     $email = $response->getEmail() ? $response->getEmail() : $username;
     $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($username);
         $user->setEmail($email);
         $user->setPassword($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:poteirard,项目名称:concert-autolist,代码行数:33,代码来源:FOSUBUserProvider.php

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

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

示例4: createUserByOAuthUserResponse

 /**
  * @param UserResponseInterface|ResourceResponse $response
  *
  * @return UserInterface
  */
 protected function createUserByOAuthUserResponse(UserResponseInterface $response)
 {
     /** @var DoSUserInterface $user */
     $user = $this->userFactory->createNew();
     /** @var CustomerInterface $customer */
     $customer = $this->customerFactory->createNew();
     // set default values taken from OAuth sign-in provider account
     // todo: check security configuration provide by `fos....username_email`
     if (null === $response->getEmail()) {
         throw new AccountNoEmailException();
     }
     // set default values taken from OAuth sign-in provider account
     if (null !== ($email = $response->getEmail())) {
         $customer->setEmail($email);
     }
     if (!$user->getUsername()) {
         $user->setUsername($response->getEmail() ?: $response->getNickname());
     }
     // set random password to prevent issue with not nullable field & potential security hole
     $user->setPlainPassword(substr(sha1($response->getAccessToken()), 0, 10));
     $user->setDisplayName($response->getNickname());
     $user->setLocale($response->getLocale());
     $user->setCustomer($customer);
     $user->confirmed();
     $customer->setFirstName($response->getFirstName());
     $customer->setLastName($response->getLastName());
     $customer->setGender($response->getGender() ?: CustomerInterface::UNKNOWN_GENDER);
     $customer->setBirthday($response->getBirthday());
     return $this->updateUserByOAuthUserResponse($user, $response);
 }
开发者ID:liverbool,项目名称:dos-user-bundle,代码行数:35,代码来源:UserProvider.php

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

示例6: createUserByOAuthUserResponse

 /**
  * Ad-hoc creation of user
  *
  * @param UserResponseInterface $response
  *
  * @return SyliusUserInterface
  */
 protected function createUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $user = $this->userManager->createUser();
     // set default values taken from OAuth sign-in provider account
     if (null !== ($email = $response->getEmail())) {
         $user->setEmail($email);
     }
     if (!$user->getUsername()) {
         $user->setUsername($response->getEmail());
     }
     // set random password to prevent issue with not nullable field & potential security hole
     $user->setPlainPassword(substr(sha1($response->getAccessToken()), 0, 10));
     $user->setEnabled(true);
     return $this->updateUserByOAuthUserResponse($user, $response);
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:22,代码来源:UserProvider.php

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

示例8: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     //Data from response
     $email = $response->getEmail();
     $firstname = $response->getFirstName();
     $lastname = $response->getLastName();
     $nickname = $firstname . $lastname;
     //Check if this user already exists in our app DB
     $qb = $this->doctrine->getManager()->createQueryBuilder();
     $qb->select('u')->from('AppBundle:Person', 'u')->where('u.email = :gmail')->setParameter('gmail', $email)->setMaxResults(1);
     $result = $qb->getQuery()->getResult();
     //add to database if doesn't exists
     if (!count($result)) {
         $person = new Person();
         $person->setFirstname($firstname);
         $person->setLastname($lastname);
         $person->setUsername($nickname);
         $person->setEmail($email);
         //$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($person);
         $password = $encoder->encodePassword(md5(uniqid()), $person->getSalt());
         $person->setPassword($password);
         $em = $this->doctrine->getManager();
         $em->persist($person);
         $em->flush();
     } else {
         $person = $result[0];
     }
     //set id
     $this->session->set('id', $person->getId());
     return $person;
 }
开发者ID:howest-wsde,项目名称:VrijwilligersTool,代码行数:34,代码来源:OAuthProvider.php

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

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

示例11: loadUserByOAuthUserResponse

 /**
  * @inheritdoc
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     try {
         $user = $this->userManager->findUser($response->getEmail());
     } catch (\Exception $e) {
         $username = $response->getEmail();
         $firstName = $response->getFirstName() != '' ? $response->getFirstName() : $response->getNickName();
         $lastName = $response->getLastName() != '' ? $response->getLastName() : '';
         try {
             $user = $this->userManager->createNewUser($username, $response->getEmail(), $firstName, $lastName);
         } catch (\Exception $e) {
             throw $e;
         }
     }
     return new User($user);
 }
开发者ID:crevillo,项目名称:ezsocialloginbundle,代码行数:19,代码来源:EzSocialUserProvider.php

示例12: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $username = $response->getUsername();
     $user = $this->userManager->findUserByUsernameOrEmail($response->getEmail());
     //$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
     if (null === $user) {
         $user = $this->userManager->createUser();
         $this->linkUserToOAuthAccount($response, $user);
         $user->setUsername($response->getUsername());
         if ($response->getEmail() == null) {
             $email = $response->getUsername() . "@ddd.com";
         } else {
             $email = $response->getEmail();
         }
         $user->setEmail($email);
         $user->setPassword($username);
         $user->setEnabled(true);
         $this->userManager->updateUser($user);
         return $user;
     }
     //if user exists - go with the HWIOAuth way
     try {
         $user = parent::loadUserByOAuthUserResponse($response);
     } catch (AccountNotLinkedException $e) {
         $this->linkUserToOAuthAccount($response, $user);
         $this->userManager->updateUser($user);
     }
     $serviceName = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($serviceName) . 'AccessToken';
     //update access token
     $user->{$setter}($response->getAccessToken());
     return $user;
 }
开发者ID:bonesmccoy,项目名称:symfex,代码行数:36,代码来源:UserProvider.php

示例13: loadUserByOAuthUserResponse

 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     $name = $response->getRealName();
     $email = $response->getEmail();
     $clientId = $response->getUsername();
     $token = $response->getAccessToken();
     $user = $this->doctrine->getRepository('UserUserBundle:Users')->findOneByOAuthUser($clientId);
     /** @var Users $user */
     if (!$user) {
         $service = $response->getResourceOwner()->getName();
         $setter = 'set' . ucfirst($service);
         $setterId = $setter . "Id";
         $setterToken = $setter . 'AccessToken';
         $user = new Users();
         $user->setRealname($name);
         $user->setUsername($email);
         $user->{$setterId}($clientId);
         $user->{$setterToken}($token);
         $user->setPassword(sha1($clientId));
         $roles = $this->doctrine->getRepository('UserUserBundle:Roles')->findOneBy(['role' => 'ROLE_USER']);
         $user->addRole($roles);
         $this->doctrine->getManager()->persist($user);
         $this->doctrine->getManager()->flush();
         $userId = $user->getId();
     } else {
         $userId = $user->getId();
     }
     if (!$userId) {
         throw new UsernameNotFoundException('Возникла проблема добавления или определения пользователя');
     }
     return $this->loadUserByUsername($userId);
 }
开发者ID:rdbn,项目名称:shopsnmarkets,代码行数:32,代码来源:OAuthProvider.php

示例14: loadUserByOAuthUserResponse

 /**
  * {@inheritdoc}
  */
 public function loadUserByOAuthUserResponse(UserResponseInterface $response)
 {
     if (!$this->cm->get('oro_sso.enable_google_sso')) {
         throw new \Exception('SSO is not enabled');
     }
     $username = $response->getUsername();
     if ($username === null) {
         throw new BadCredentialsException('Bad credentials');
     }
     if (!$this->isEmailEnabledForOauth($response->getEmail())) {
         throw new EmailDomainNotAllowedException('Bad credentials');
     }
     $user = $this->userManager->findUserBy([$this->getOAuthProperty($response) => $username]);
     if (!$user) {
         $user = $this->userManager->findUserByEmail($response->getEmail());
         if ($user) {
             $user->setGoogleId($username);
             $this->userManager->updateUser($user);
         }
     }
     if (!$user || !$user->isEnabled()) {
         throw new BadCredentialsException('Bad credentials');
     }
     return $user;
 }
开发者ID:nmallare,项目名称:platform,代码行数:28,代码来源:OAuthUserProvider.php

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


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