本文整理汇总了PHP中HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface类的典型用法代码示例。如果您正苦于以下问题:PHP UserResponseInterface类的具体用法?PHP UserResponseInterface怎么用?PHP UserResponseInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserResponseInterface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: importProfileLinkedinAction
public function importProfileLinkedinAction(Request $request, UserResponseInterface $response)
{
$data = $response->getResponse();
/* this method should return all data that was sent from resource owner ???*/
var_dump($data);
exit;
}
开发者ID:medy36,项目名称:OauthSymfony,代码行数:7,代码来源:DefaultController.php
示例2: 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;
}
开发者ID:jraisanen,项目名称:user-bundle,代码行数:31,代码来源:FOSUBUserProvider.php
示例3: 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;
}
}
开发者ID:alfonsomga,项目名称:symfony.demo.on.roids,代码行数:37,代码来源:UserProvider.php
示例4: 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;
}
}
开发者ID:ryota-murakami,项目名称:daily-tweet,代码行数:26,代码来源:OAuthEntityUserProvider.php
示例5: 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
示例6: 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;
}
开发者ID:lahiiru,项目名称:Quota,代码行数:35,代码来源:FOSUBUserProvider.php
示例7: loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
//$doctrine = $em = $this->getEntityManager();
//echo 'fsfd';
//print_r($doctrine);
//die;
try {
$userdata = $response->getResponse();
$fbid = $userdata['id'];
$name = $userdata['name'];
$email = $userdata['email'];
print_r($userdata);
$user = $this->_em->createQueryBuilder()->select('u')->from('Yasoon\\Site\\Entity\\AuthorEntity', 'u')->where('u.facebookId = :fbid')->setParameter('fbid', $fbid)->getQuery()->getSingleResult();
if (!is_object($user)) {
$user = (new AuthorEntity())->setName($name)->setEmail('')->setPassword('')->setSubscribed(1)->setFacebookId($fbid)->setPublicationDate(new \DateTime())->setRole(1);
$this->_em->persist($user);
$this->_em->flush();
}
} catch (\Exception $e) {
return ['error' => true, 'errorText' => $e->getMessage()];
}
//$user = $this->_em->getRepository('Yasoon\Site\Entity\AuthorEntity')->find(41);
//print_r($user->getName());
return $user;
}
开发者ID:yasoon,项目名称:yasoon,代码行数:25,代码来源:AuthorFacebookRepository.php
示例8: 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
示例9: 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
示例10: 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
示例11: 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
示例12: loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
// echa($response->getAccessToken());
// echa($response->getResponse(), __FILE__);
// -- Load user's data from P4S
$data = $response->getResponse();
if (null != $data && array_key_exists('status', $data) && ResponseHelper::OK == $data['status'] && array_key_exists('data', $data) && null != $data['data']) {
$p4sId = $data['data']['id'];
} else {
throw new UsernameNotFoundException("Unable to load this user info");
}
$result = $this->em->getRepository('Amisure\\P4SApiBundle\\Entity\\User\\SessionUser')->findOneBy(array('username' => $p4sId));
// - Create an account
if (null == $result) {
$user = $this->fillUser($data['data']);
$this->createNewUser($user);
} else {
// $user = $result;
$user = $this->fillUser($data['data']);
$user->setId($result->getId());
}
// -- Save access token
$this->session->set('access_token', $response->getAccessToken());
return $user;
}
开发者ID:trialog,项目名称:p4s-api-bundle,代码行数:25,代码来源:UserProvider.php
示例13: handleResponse
public function handleResponse(UserResponseInterface $response, UserService $userService)
{
$fields = $response->getResponse();
$gitHubLogin = $fields['login'];
$accessToken = $response->getAccessToken();
$user = $userService->findByGitHubLogin($gitHubLogin);
if (null === $user) {
throw new UsernameNotFoundException();
}
$oAuthUser = new OAuthUser($user);
$oAuthUser->addRole('ROLE_GITHUB_USER');
$oAuthUser->setAccessToken($accessToken);
if (array_key_exists('name', $fields)) {
$gitHubName = $fields['name'];
$oAuthUser->setRealName($gitHubName);
} else {
$oAuthUser->setRealName($gitHubLogin);
}
$client = new Client();
$client->setOption('api_version', 'v3');
$client->authenticate($response->getAccessToken(), Client::AUTH_HTTP_TOKEN);
/* @var \Github\Api\CurrentUser $currentUserApi */
$currentUserApi = $client->api('current_user');
$emails = $currentUserApi->emails();
$allEMails = $emails->all();
$oAuthUser->setEmail($this->getPrimaryEmailAddress($allEMails));
return $oAuthUser;
}
开发者ID:terretta,项目名称:gitki.php,代码行数:28,代码来源:GitHubResponseHandler.php
示例14: loadUserByOAuthUserResponse
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$username = $response->getUsername();
$email = $response->getEmail();
$nickname = $response->getNickname();
$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->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:kvartiri,项目名称:kvartiri,代码行数:36,代码来源:FOSUBUserProvider.php
示例15: 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
示例16: loadUserByOAuthUserResponse
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$username = $response->getUsername();
$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
//when the user is registering
if (null === $user) {
$realName = $response->getRealName();
if ($realName !== null) {
$extractName = explode(" ", $realName);
$firstName = $extractName[0];
$lastName = end($extractName);
}
$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($response->getNickname());
$user->setEmail($response->getEmail());
$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;
}
开发者ID:bishnupradhan,项目名称:sf2odm,代码行数:38,代码来源:FOSUBUserProvider.php
示例17: loadUserByOAuthUserResponse
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$data = $response->getResponse();
$username = $response->getUsername();
$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
$service = $response->getResourceOwner()->getName();
//when the user is registrating
if (null === $user) {
if ($service == "google") {
$service = "gplus";
}
$setter = 'set' . ucfirst($service);
$setter_id = $setter . 'Uid';
$setter_token = $setter . 'Name';
// create new user here
// TODO: Check email, if exist add service
$userE = $this->userManager->findUserBy(array("email" => $response->getEmail()));
if (null === $userE) {
$user = $this->userManager->createUser();
$user->setUsername($response->getEmail());
if ($service == "gplus") {
$user->setFirstname($data['given_name']);
}
if ($service == "facebook") {
$name = explode(" ", $data['name']);
$user->setFirstname($name[0]);
$user->setLastname($name[1]);
}
$user->setEmail($response->getEmail());
$user->setPassword("");
} else {
$user = $userE;
}
$user->{$setter_id}($username);
$user->{$setter_token}($response->getAccessToken());
$user->setEnabled(true);
// Customfields
$user->setProfilePicture($response->getProfilePicture());
//TODO: Save Locale, $user->setLocale($response->getLocale());
$this->userManager->updateUser($user);
return $user;
}
//if user exists - go with the HWIOAuth way
$user = parent::loadUserByOAuthUserResponse($response);
$serviceName = $response->getResourceOwner()->getName();
if ($serviceName == "google") {
$serviceName = "gplus";
}
$setter = 'set' . ucfirst($serviceName) . 'Name';
//update access token
$user->{$setter}($response->getAccessToken());
//update custom fields
//TODO: Check google response, facebook?
if ($service == "facebook") {
$url = "http://graph.facebook.com/" . $data['id'] . "/picture?type=normal";
$user->setProfilePicture($url);
}
return $user;
}
开发者ID:alejandro-arrabal,项目名称:BasicSymfony,代码行数:62,代码来源:FOSUBUserProvider.php
示例18: 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];
}
开发者ID:rafalwrzeszcz,项目名称:HWIOAuthBundle,代码行数:17,代码来源:FOSUBUserProvider.php
示例19: 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;
}
开发者ID:lukaszmakuch,项目名称:question-sheet-storage,代码行数:12,代码来源:UserRepo.php
示例20: loadUserByOAuthUserResponse
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$authProviderName = $response->getResourceOwner()->getName();
$username = $response->getResponse()['login'];
$this->session->set('owner', $authProviderName);
$this->session->set('username', $username);
return $this->loadUserByUsername($username);
}
开发者ID:ramondelafuente,项目名称:haphpy-birthday,代码行数:11,代码来源:UserProvider.php
注:本文中的HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论