當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。