本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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();
}
示例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;
}
}
示例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()]);
}
示例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];
}
示例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;
}