/**
  * Initialize view action
  *
  * @param \TYPO3\Flow\Mvc\View\ViewInterface $view
  * @return void
  */
 protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view)
 {
     $loggedUser = $this->securityContext->getAccount();
     $currentUrl = $this->request->getHttpRequest()->getUri();
     $view->assign('currentpage', $currentUrl);
     $view->assign('state', $this->base64UrlEncode($currentUrl));
     if ($loggedUser != NULL) {
         $view->assign('loggedInUser', $this->securityContext->getAccount()->getAccountIdentifier());
         $view->assign('currentUser', $this->securityContext->getAccount()->getParty());
     }
     $facebook_appid = $this->facebookService->getAppId();
     $facebook_redirecturi = $this->facebookService->getRedirectUri();
     $vkLoginUrl = $this->vkService->getAuthorizationUri();
     $this->view->assignMultiple(array('vk_url' => $vkLoginUrl, 'google_url' => $this->googlePlusService->getAuthorizationUri(), 'facebook_appid' => $facebook_appid, 'facebook_redirecturi' => $facebook_redirecturi));
 }
Example #2
0
 /**
  * @param string $social
  * @return void
  */
 public function socialAction($social = NULL)
 {
     $args = $this->request->getArguments();
     switch ($social) {
         case "facebook":
             if ($args['connectorjson'] !== NULL) {
                 $response = json_decode($args['connectorjson'], true);
                 $token = $response['accessToken'];
                 $facebookAccounts = $this->facebookService->getAccounts($token);
                 $facebookImage = "https:////graph.facebook.com/" . $facebookAccounts['id'] . "/picture?type=large";
                 $this->createSocialAccount('facebook-' . $facebookAccounts['id'], $facebookAccounts['id'], $facebookAccounts['id'], $facebookAccounts['first_name'], $facebookAccounts['last_name'], $facebookImage, $facebookAccounts['email'], $network = "facebook", $args['return_url']);
             } else {
                 $this->addFlashMessage("access_denied");
                 $this->redirect('index', 'Standard');
             }
             break;
         case "vk":
             if (isset($args['code']) && $args['code'] !== NULL) {
                 $token = $this->vkService->getToken($args['code']);
                 if (isset($token['error']) && $token['error'] != NULL) {
                     $this->addFlashMessage($token['error']);
                     $this->redirect('index', 'Standard');
                 }
                 $data = json_decode($token);
                 $vkAccounts = $this->vkService->getAccounts($data->access_token, $data->user_id);
                 if ($args['state'] !== null) {
                     $returnUrl = $this->base64UrlDecode($args['state']);
                 }
                 $this->createSocialAccount('vk-' . $vkAccounts['response'][0]['uid'], $vkAccounts['response'][0]['uid'], $vkAccounts['response'][0]['uid'], $vkAccounts['response'][0]['first_name'], $vkAccounts['response'][0]['last_name'], $vkAccounts['response'][0]['photo_big'], $data->email, $network = "vk", $returnUrl);
             } else {
                 $this->addFlashMessage("access_denied");
                 $this->redirect('index', 'Standard');
             }
             break;
         case "googleplus":
             if (isset($args['code']) && $args['code'] !== NULL) {
                 $token = $this->googlePlusService->getToken($args['code']);
                 if (!isset($token->access_token)) {
                     $this->addFlashMessage($token->error_description);
                     $this->redirect('index', 'Standard');
                 }
                 $googleAccounts = $this->googlePlusService->getAccounts($token->access_token);
                 if ($args['state'] !== null) {
                     $returnUrl = $this->base64UrlDecode($args['state']);
                 }
                 $this->createSocialAccount('googlePlus-' . $googleAccounts['id'], $googleAccounts['id'], $googleAccounts['id'], $googleAccounts['name']['familyName'], $googleAccounts['name']['givenName'], $googleAccounts['image']['url'], $googleAccounts['emails'][0]['value'], $network = "googlePlus", $returnUrl);
             } else {
                 $this->addFlashMessage("access_denied");
                 $this->redirect('index', 'Standard');
             }
             break;
         case "twitter":
             if (isset($args['oauth_verifier']) && $args['oauth_verifier'] !== NULL) {
                 $response = $this->twitterService->getToken($args['oauth_verifier']);
                 $returnUrl = $this->base64UrlDecode($this->session->getData('return_url'));
                 if ($response !== NULL) {
                     $user_id = $response['user_id'];
                     $fullName = explode(" ", $response['since_id']->name);
                     $this->createSocialAccount('twitter-' . $user_id, $user_id, $user_id, $fullName[0], $fullName[1], $response['since_id']->profile_image_url, '', $network = "twitter", $returnUrl);
                 }
             } else {
                 $this->addFlashMessage('Something get wrong. Please, try again.', "Error", 'Error');
                 $this->redirect('index', 'Standard');
             }
             break;
     }
 }