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;
 }
Example #2
0
 public function loadUserByUsername($username)
 {
     $user = $this->userService->findByEmail($username);
     if (null === $user) {
         throw new UsernameNotFoundException();
     }
     return $user;
 }
 public function handleResponse(UserResponseInterface $response, UserService $userService)
 {
     $fields = $response->getResponse();
     $email = $fields['email'];
     $login = explode('@', $email)[0];
     $user = $userService->findByGoogleLogin($login);
     if (null === $user) {
         throw new UsernameNotFoundException();
     }
     $oAuthUser = new OAuthUser($user);
     $oAuthUser->addRole('ROLE_GOOGLE_USER');
     $oAuthUser->setAccessToken($response->getAccessToken());
     $oAuthUser->setRealName($fields['name']);
     $oAuthUser->setEmail($email);
     return $oAuthUser;
 }
Example #4
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  * @param User            $user
  * @param QuestionHelper  $questionHelper
  * @param UserService     $userService
  *
  * @return User
  */
 protected function editPassword(InputInterface $input, OutputInterface $output, User $user, QuestionHelper $questionHelper, UserService $userService)
 {
     $passwordQuestion = new Question('Password (leave blank to disable form login): ');
     $passwordQuestion->setHidden(true);
     $passwordQuestion->setHiddenFallback(false);
     $passwordQuestion->setMaxAttempts(3);
     $password = $questionHelper->ask($input, $output, $passwordQuestion);
     if (null !== $password) {
         $user = $userService->changePassword($user, $password);
     } else {
         $user->setPassword(null);
     }
     return $user;
 }