本文整理汇总了PHP中HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface::getRealName方法的典型用法代码示例。如果您正苦于以下问题:PHP UserResponseInterface::getRealName方法的具体用法?PHP UserResponseInterface::getRealName怎么用?PHP UserResponseInterface::getRealName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HWI\Bundle\OAuthBundle\OAuth\Response\UserResponseInterface
的用法示例。
在下文中一共展示了UserResponseInterface::getRealName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例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
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());
}
示例5: 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);
}
示例6: loadUserByOAuthUserResponse
/**
* @param UserResponseInterface $response
* @return User
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$username = $response->getUsername();
/** @var User $user */
$user = $this->userManager->findUserBy(['slackUserName' => $response->getUsername()]);
if ($user === null) {
$user = $this->userManager->createUser();
$user->setSlackUserName($username);
$user->setSlackAccessToken($response->getAccessToken());
$user->setUsername($response->getNickname());
$user->setEmail($response->getEmail());
$user->setRealName($response->getRealName());
$user->setPassword($username);
$user->setEnabled(true);
$this->userManager->updateUser($user);
$token = new Token($user);
$this->tokenRepository->persist($token);
$user->addToken($token);
$this->userManager->updateUser($user);
return $user;
}
$user = parent::loadUserByOAuthUserResponse($response);
$user->setSlackAccessToken($response->getAccessToken());
$user->setRealName($response->getRealName());
$token = new Token($user);
$this->tokenRepository->persist($token);
$user->addToken($token);
$this->userManager->updateUser($user);
return $user;
}
示例7: 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()]);
}
示例8: createUserFromResponse
/**
* Create user from response
*
* @param UserResponseInterface $response
*
* @return User
*/
private function createUserFromResponse(UserResponseInterface $response)
{
/** @var User $user User */
$user = $this->userManager->createUser();
$user->setUsername($response->getUsername())->setFullName($response->getRealName())->setEmail($response->getEmail())->setEnabled(true)->setPlainPassword(uniqid())->setFacebookId($response->getUsername())->setFacebookAccessToken($response->getAccessToken());
$this->eventDispatcher->dispatch(AppEvents::FACEBOOK_USER_CONNECTED, new FacebookUserConnectedEvent($user));
$this->userManager->updateUser($user);
return $user;
}
示例9: 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;
}
}
示例10: loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
//Data from Google response
$social_id = $response->getUsername(); /* An ID like: 112259658235204980084 */
$email = $response->getEmail();
$nickname = $response->getNickname();
$realname = $response->getRealName();
$avatar = $response->getProfilePicture();
//set data in session
$this->session->set('email', $email);
$this->session->set('nickname', $nickname);
$this->session->set('realname', $realname);
$this->session->set('avatar', $avatar);
//Check if this Google user already exists in our app DB
$qb = $this->doctrine->getManager()->createQueryBuilder();
$qb->select('u')
->from('BloggerBlogBundle:User', 'u')
->where('u.socialId = :sid')
->setParameter('sid', $social_id)
->setMaxResults(1);
$result = $qb->getQuery()->getResult();
//add to database if doesn't exists
if (!count($result)) {
$user = new User();
$user->setUsername($social_id);
$user->setRealname($realname);
$user->setNickname($nickname);
$user->setEmail($email);
$user->setSocialId($social_id);
//$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($user);
$password = $encoder->encodePassword(md5(uniqid()), $user->getSalt());
$user->setPassword($password);
$em = $this->doctrine->getManager();
$em->persist($user);
$em->flush();
} else {
$user = $result[0]; /* return User */
}
//set id
$this->session->set('id', $user->getId());
return $this->loadUserByUsername($response->getUsername());
}
示例11: register
private function register(UserResponseInterface $response)
{
$username = $response->getRealName();
$email = $response->getEmail();
$password = $response->getUsername();
$service = $response->getResourceOwner()->getName();
$client = $this->container->get('doctrine')->getRepository('BoundCoreBundle:Client')->findOneBy(array($service . '_id' => $password));
if ($client instanceof Client) {
$this->session->getFlashBag()->add('error', "Client ID already bound.");
} else {
$user = $this->container->get('bound.user_manager')->add($username, $email, $password, true);
$this->link($response, $user);
return $user;
}
}
示例12: loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$user = $this->userRepository->findOneBy(['spotifyId' => $response->getUsername()]);
if (!$user instanceof SpotifyUser) {
$user = new SpotifyUser($response->getUsername());
}
$user->setSpotifyId($response->getUsername())->setDisplayName($response->getRealName())->setAccessToken($response->getAccessToken())->setAccessTokenExpires(time() + $response->getExpiresIn())->setRefreshToken($response->getRefreshToken())->setProfileUrl($response->getResponse()['href']);
$responseHasImages = isset($response->getResponse()['images']) && is_array($response->getResponse()['images']);
$responseImageExists = array_key_exists('url', $response->getResponse()['images'][0]);
if ($responseHasImages && $responseImageExists) {
$user->setImageUrl($response->getResponse()['images'][0]['url']);
}
$this->em->persist($user);
$this->em->flush();
return $this->loadUserByUsername($user->getUsername());
}
示例13: 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) {
if (empty($response->getEmail())) {
$message = sprintf("User not found. Please register first and then connect the account from your profile.", $username);
throw new AccountNotLinkedException($message);
}
$fullName = $response->getRealName();
$parts = explode(" ", $fullName);
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);
$user = $this->userManager->createUser();
$user->setEnabled(true);
$user->setUsername($response->getUsername());
$user->setEmail($response->getEmail());
$user->setPlainPassword(bin2hex(random_bytes(5)));
$user->setFirstName($firstname);
$user->setLastName($lastname);
$this->userManager->updateUser($user);
$connection = new UserOauthAccount();
$connection->setUser($user);
$connection->setProvider($service);
$connection->setProviderId($response->getUsername());
}
$connection->setToken($response->getAccessToken());
$this->em->persist($connection);
$this->em->flush();
return $connection->getUser();
}
示例14: loadUserByOAuthUserResponse
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$username = $response->getUsername();
$email = $response->getEmail();
$nickname = $response->getNickname();
$realname = $response->getRealName();
$user = $this->userManager->findUserBy(array($this->getProperty($response) => $username));
if (null === $user) {
$service = $response->getResourceOwner()->getName();
$setter = 'set' . ucfirst($service);
$setter_id = $setter . 'Id';
$user = $this->userManager->createUser();
$user->{$setter_id}($username);
$user->setUsername($username);
$user->setRealname($realname);
$user->setNickname($nickname);
$user->setEmail($email);
$user->setPlainPassword($username);
$user->setEnabled(true);
$this->userManager->updateUser($user);
}
return $this->loadUserByUsername($response->getUsername());
}
示例15: loadUserByOAuthUserResponse
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
$userTokenId = $response->getUsername();
// it is user id in social network
// $email = $response->getEmail();
$userNameLastName = $response->getRealName();
// name + lastname
$userNameLastName = explode(" ", $userNameLastName);
$service = $response->getResourceOwner()->getName();
switch ($service) {
case "facebook":
if (count($userNameLastName) > 1) {
$realName = $userNameLastName[0];
$realLastName = $userNameLastName[1];
} else {
$realName = $userNameLastName[0];
$realLastName = null;
}
break;
case "vkontakte":
if (count($userNameLastName) > 1) {
$realName = $userNameLastName[1];
$realLastName = $userNameLastName[0];
} else {
$realName = $userNameLastName[0];
$realLastName = null;
}
break;
default:
if (count($userNameLastName) > 1) {
$realName = $userNameLastName[0];
$realLastName = $userNameLastName[1];
} else {
$realName = $userNameLastName[0];
$realLastName = null;
}
break;
}
// Lets create toke service _ id (for example 213123424_facebook)
$accessToken = $userTokenId . "_" . $service;
// find by name
$user = $this->userManager->findUserBy(array("username" => $accessToken));
//when the user is registrating
if (null === $user) {
try {
// create new user here
$user = $this->userManager->createUser();
$user->setUsername($accessToken);
$user->setFirstname($realName);
if (!is_null($realLastName)) {
$user->setLastname($realLastName);
}
//email can be null
// Lets use default email
$user->setEmail($accessToken . "@table4you.com");
// encode password
$factory = $this->container->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$password = $encoder->encodePassword($userTokenId, $user->getSalt());
$user->setPassword($password);
$user->setEnabled(true);
if (null === $user->getConfirmationToken()) {
/** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
$tokenGenerator = $this->container->get('fos_user.util.token_generator');
$user->setConfirmationToken($tokenGenerator->generateToken());
}
$this->userManager->updateUser($user);
// We should send confirmation email
// $mailer = $this->container->get('fos_user.mailer');
// $mailer->sendConfirmationEmailMessage($user);
return $user;
} catch (Exception $ex) {
throw new AccessDeniedException();
}
}
//if user exists - go with the HWIOAuth way
return $user;
}