/** * Vue Resource. * * @see Configuration https://github.com/vuejs/vue-resource/blob/master/docs/config.md * @see HTTP Requests/Response https://github.com/vuejs/vue-resource/blob/master/docs/http.md * @see Creating Resources https://github.com/vuejs/vue-resource/blob/master/docs/resource.md * @see Code Recipes https://github.com/vuejs/vue-resource/blob/master/docs/recipes.md * * @param array $options * @param array $headers */ public static function resource(array $options = [], array $headers = []) { if (!static::inited(__METHOD__)) { static::core(); static::addJS(static::phoenixName() . '/js/vue/vue-resource.min.js'); $defaultOptions = ['root' => Ioc::getUriData()->path]; $options = static::getJSObject($defaultOptions, $options); $defaultHealders = ['common' => ['X-Csrf-Token' => CsrfProtection::getFormToken()]]; $headers = static::mergeOptions($defaultHealders, $headers); $headers = array_intersect_key($headers, array_flip(['common', 'custom', 'delete', 'patch', 'post', 'put'])); $js[] = "// Init Vue-resource http settings."; $js[] = "Vue.http.options = Object.assign({}, Vue.http.options, {$options});"; foreach ($headers as $key => $headerLines) { if (count($headerLines)) { $js[] = "Vue.http.headers.{$key} = Object.assign({}, Vue.http.headers.{$key}, " . static::getJSObject($headerLines) . ");"; } } static::internalJS(implode("\n", $js)); } }
/** * csrfToken * * @param string $token * * @return void */ public static function csrfToken($token = null) { if (!static::inited(__METHOD__, get_defined_vars())) { // Inject Token to meta HtmlHeader::addMetadata('csrf-token', $token ?: CsrfProtection::getFormToken()); } }
/** * doAuthenticate * * @param string $provider * @param \Hybrid_Auth $auth * * @return \Hybrid_Provider_Adapter * @throws \OutOfRangeException */ protected function doAuthenticate($provider, \Hybrid_Auth $auth) { $package = $this->warder->app->getPackage(); $callbackUrl = $package->router->route('social_login', array('provider' => $provider, CsrfProtection::getFormToken() => 1), CoreRouter::TYPE_FULL); return $auth->authenticate($provider, array('hauth_return_to' => $callbackUrl)); }
/** * ajax * * @param bool $token * * @return void */ public static function ajax($token = true) { if (!static::inited(__METHOD__)) { static::addJS(static::phoenixName() . '/js/phoenix/ajax.min.js'); } if (!static::inited(__METHOD__, (bool) $token) && $token) { $token = CsrfProtection::getFormToken(); static::internalJS("Phoenix.Ajax.headers._global['X-Csrf-Token'] = '{$token}'"); } }