示例#1
0
 public function actionAuth()
 {
     if ($code = $this->_input->filterSingle('code', XenForo_Input::STRING)) {
         $response = DigitalPointBetterAnalytics_Helper_Reporting::exchangeCodeForToken($code);
         if (!empty($response->error) && !empty($response->error_description)) {
             return $this->responseError(new XenForo_Phrase('invalid_google_api_code', array('error' => $response->error, 'description' => $response->error_description)));
         }
         if (empty($response->expires_in)) {
             return $this->responseError(new XenForo_Phrase('unknown_google_api_error', array('dump' => nl2br(var_export($response, true))), false));
         }
         $response->expires_at = XenForo_Application::$time + $response->expires_in - 100;
         unset($response->expires_in);
         XenForo_Model::create('XenForo_Model_Option')->updateOption('dpAnalyticsTokens', json_encode($response));
         return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, XenForo_Link::buildAdminLink('options/list/stats'));
     }
     if (!XenForo_Application::getOptions()->dpAnalyticsCredentials['client_id'] || !XenForo_Application::getOptions()->dpAnalyticsCredentials['client_secret']) {
         return $this->responseError(new XenForo_Phrase('no_credentials_found'));
     }
     return $this->responseRedirect(XenForo_ControllerResponse_Redirect::SUCCESS, DigitalPointBetterAnalytics_Helper_Reporting::getAuthenticationUrl());
 }