Пример #1
0
 /**
  * Add social login
  */
 private function _addSocialLogin()
 {
     $isSocialLogin = false;
     if ($this->config->social->facebook->appID) {
         $fb = ZFacebook::getInstance();
         $helper = $fb->getRedirectLoginHelper();
         $permissions = $this->config->social->facebook->permissions->toArray();
         $this->view->setVar('facebookLoginUrl', $helper->getLoginUrl(BASE_URI . '/auth/facebook/login-callback/', $permissions));
         $isSocialLogin = true;
     }
     if ($this->config->social->google->clientID) {
         $google = ZGoogle::getInstance();
         $this->view->setVar('googleLoginUrl', $google->getAuthUrl());
         $isSocialLogin = true;
     }
     $this->view->setVar('isSocialLogin', $isSocialLogin);
 }
Пример #2
0
 /**
  * Login callback
  */
 public function loginAction()
 {
     $error = $this->request->get('error', 'string');
     if ($error) {
         $this->response->redirect('/');
         return;
     }
     $fb = ZFacebook::getInstance();
     $accessToken = null;
     $helper = $fb->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
     } catch (\Exception $e) {
         $this->flashSession->notice('_ZT_Cannot access');
         $this->response->redirect('/user/login/');
         return;
     }
     if (isset($accessToken)) {
         // Logged in!
         $this->session->set('_SOCIAL_FACEBOOK_ACCESS_TOKEN', (string) $accessToken);
         $fb->setDefaultAccessToken((string) $accessToken);
         try {
             $response = $fb->get('/me?fields=email,first_name,last_name');
             $userNode = $response->getGraphUser();
             $status = $this->_process($userNode);
             if ($status['success'] && $status['message'] == null) {
                 $this->response->redirect('/');
             } elseif ($status['success'] && $status['message'] != null) {
                 $this->flashSession->success($status['message']);
                 $this->response->redirect('/user/login/');
             } elseif (!$status['success']) {
                 $this->flashSession->notice($status['message']);
                 $this->response->redirect('/user/login/');
             }
             return;
         } catch (\Exception $e) {
             $this->flashSession->notice('_ZT_Facebook server is busy, please try again later!');
             $this->response->redirect('/user/login/');
             return;
         }
     }
 }