AuthController::socialAction PHP Method

socialAction() public method

public socialAction ( )
    public function socialAction()
    {
        $preferencesService = \Zend_Registry::get('container')->getService('system_preferences_service');
        $userService = \Zend_Registry::get('container')->getService('user');
        $session = \Zend_Registry::get('container')->getService('session');
        $config = array('base_url' => $this->view->serverUrl($this->view->url(array('action' => 'socialendpoint'))), 'debug_mode' => false, 'providers' => array('Facebook' => array('enabled' => true, 'keys' => array('id' => $preferencesService->facebook_appid, 'secret' => $preferencesService->facebook_appsecret))));
        try {
            $hauth = new Hybrid_Auth($config);
            $adapter = $hauth->authenticate($this->_getParam('provider'));
            $userData = $adapter->getUserProfile();
            $socialAdapter = $this->_helper->service('auth.adapter.social');
            $socialAdapter->setProvider($adapter->id)->setProviderUserId($userData->identifier);
            $result = $this->auth->authenticate($socialAdapter);
            if ($result->getCode() !== Zend_Auth_Result::SUCCESS) {
                $user = $this->_helper->service('user')->findOneBy(array('email' => $userData->email));
                if (!$user) {
                    $publicationService = \Zend_Registry::get('container')->getService('newscoop_newscoop.publication_service');
                    $user = $this->_helper->service('user')->createPending($userData->email, $userData->firstName, $userData->lastName, null, $publicationService->getPublication()->getId());
                }
                $this->_helper->service('auth.adapter.social')->addIdentity($user, $adapter->id, $userData->identifier);
                $this->auth->authenticate($socialAdapter);
            } else {
                $user = $this->_helper->service('user')->getCurrentUser();
                $token = $userService->loginUser($user, 'frontend_area');
                $session->set('_security_frontend_area', serialize($token));
                $OAuthtoken = $userService->loginUser($user, 'oauth_authorize');
                $session->set('_security_oauth_authorize', serialize($OAuthtoken));
            }
            setcookie('NO_CACHE', '1', null, '/', '.' . $this->extractDomain($_SERVER['HTTP_HOST']));
            if ($user->isPending()) {
                $this->_forward('confirm', 'register', 'default', array('social' => true));
            } else {
                $request = $this->getRequest();
                if ($request->getParam('_target_path')) {
                    $this->_helper->redirector->gotoUrl($request->getParam('_target_path'));
                }
                $this->_helper->redirector('index', 'dashboard');
            }
        } catch (\Exception $e) {
            throw new \Exception($e->getMessage());
        }
    }