Esempio n. 1
0
 /**
  * this method is to connect existing user with provider data
  * {@inheritDoc}
  */
 public function connect(UserInterface $user, UserResponseInterface $response)
 {
     $property = $this->getProperty($response);
     $username = $response->getUsername();
     //on connect - get the access token and the user ID
     $service = $response->getResourceOwner()->getName();
     $setter = 'set' . ucfirst($service);
     $setter_id = $setter . 'Id';
     $setter_token = $setter . 'AccessToken';
     //we "disconnect" previously connected users
     if (null !== ($previousUser = $this->userManager->findUserBy(array($property => $username)))) {
         $previousUser->{$setter_id}(null);
         $previousUser->{$setter_token}(null);
         $this->userManager->updateUser($previousUser);
     }
     //we connect current user
     $user->{$setter_id}($username);
     $user->{$setter_token}($response->getAccessToken());
     $user->setLastName($response->getNickname());
     $user->setFirstName($response->getRealName());
     $user->setPicture($response->getProfilePicture());
     $this->userManager->updateUser($user);
 }