本文整理汇总了PHP中HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface类的典型用法代码示例。如果您正苦于以下问题:PHP UserResponseInterface类的具体用法?PHP UserResponseInterface怎么用?PHP UserResponseInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserResponseInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}