Ejemplo n.º 1
0
 /**
  * @param string $youtubeId
  * @return object
  * @throws Google_Exception
  */
 public function getMeta($youtubeId)
 {
     $url = 'https://www.googleapis.com/youtube/v3/videos?id=%s&part=contentDetails&key=%s';
     $key = $this->google->getConfig()->apiKey;
     $req = new Google_Http_Request(sprintf($url, $youtubeId, $key));
     $resp = $this->google->getClient()->execute($req);
     return array_pop($resp['items']);
 }
Ejemplo n.º 2
0
 /**
  * Google get's the url for this handle when redirecting to login dialog.
  * It automatically calls the onResponse event.
  *
  * You don't have to redirect, the request before the auth process will be restored automatically.
  */
 public function handleResponse()
 {
     $this->google->getUser();
     // check the received parameters and save user
     $this->onResponse($this);
     if (!empty($this->session->last_request)) {
         $presenter = $this->getPresenter();
         try {
             $presenter->restoreRequest($this->session->last_request);
         } catch (Application\AbortException $e) {
             $refl = new \ReflectionProperty('Nette\\Application\\UI\\Presenter', 'response');
             $refl->setAccessible(TRUE);
             $response = $refl->getValue($presenter);
             if ($response instanceof Responses\ForwardResponse) {
                 $forwardRequest = $response->getRequest();
                 $params = $forwardRequest->getParameters();
                 unset($params['do']);
                 // remove the signal to the google component
                 $forwardRequest->setParameters($params);
             }
             $presenter->sendResponse($response);
         }
     }
     $this->presenter->redirect('this', array('state' => NULL, 'code' => NULL));
 }
Ejemplo n.º 3
0
 public function actionGoogleResponse()
 {
     try {
         $me = $this->google->getProfile();
         $this->registerOrLogin($me, function ($id) {
             return $this->orm->users->getByGoogleId($id);
         }, function (User $user, $me) {
             $user->googleId = $me->id;
             $token = $this->google->getAccessToken()['access_token'];
             $user->googleAccessToken = $this->aes->encrypt($token);
         }, 'google');
     } catch (Google_Exception $e) {
         $this->log->addAlert('Google login request failed', ['error' => $e->getMessage()]);
         $this->flashError('auth.flash.google.error');
     }
     $this->redirect('Auth:in');
 }
 /** @return GoogleLoginDialog */
 protected function createComponentGoogleLogin()
 {
     /** @var GoogleLoginDialog $dialog */
     $dialog = $this->google->createLoginDialog();
     $presenter = $this;
     $dialog->onResponse[] = function (GoogleLoginDialog $dialog) use($presenter) {
         $google = $dialog->getGoogle();
         if (!($google->getUser() && $google->getProfile())) {
             $presenter->flashMessageLoginFailed('Google');
             return;
         }
         try {
             $googleUser = $google->getUser();
             $googleProfile = $google->getProfile();
             $presenter->getUser()->login($presenter->usersFacade->authenticateUserFromGoogle($googleUser, $googleProfile));
             $presenter->flashMessageLoginSuccess('Google');
             $presenter->finalRedirect();
         } catch (\Google_Exception $e) {
             $presenter->flashMessageLoginFailed('Google');
         }
         $presenter->redirect('login');
     };
     return $dialog;
 }