public function authenticate() { // Load the provider $provider = Provider::forge($this->provider, $this->config); // Grab a callback from the config if ($provider->callback === null) { $provider->callback = Uri::create(Config::get('autho.urls.callback', \Request::active()->route->segments[0] . '/callback')); $provider->callback = rtrim($provider->callback, '/') . '/' . $this->provider; } $provider->authorize(array('redirect_uri' => $provider->callback)); }
/** * This method will be called after we route to the destinated method * * @access public * @return void */ public function before() { $this->language = Factory::get_language(); $this->user = Auth::make('user')->get(); Event::trigger('controller_before'); if (Request::is_hmvc()) { $this->set_content_type = false; } Restserver::auth(); return parent::before(); }
/** * This method will be called after we route to the destinated method * * @access public */ public function before() { $this->language = \Hybrid\Factory::get_language(); $this->user = \Hybrid\Acl_User::get(); \Event::trigger('controller_before'); if (\Hybrid\Request::main() !== \Hybrid\Request::active()) { $this->set_content_type = false; } \Hybrid\Restful::auth(); return parent::before(); }
public function authenticate() { // Create an consumer from the config $consumer = Consumer::forge($this->config); // Load the provider $provider = Provider::forge($this->provider); // Create the URL to return the user to $callback = Arr::get($this->config, 'callback') ?: Uri::create(Config::get('autho.urls.callback', \Request::active()->route->segments[0] . '/callback')); $callback = rtrim($callback, '/') . '/' . $this->provider; // Add the callback URL to the consumer $consumer->callback($callback); // Get a request token for the consumer $token = $provider->request_token($consumer); // Store the token Cookie::set('oauth_token', base64_encode(serialize($token))); // Redirect to the twitter login page Response::redirect($provider->authorize_url($token, array('oauth_callback' => $callback))); }
/** * Prepare Rest request * * @access protected */ protected function prepare_rest() { if (Request::main() !== Request::active()) { $this->set_content_type = false; } $this->template = null; Restserver::auth(); }
/** * Parse URI structure and get current_page * * @access protected * @return void */ protected function initiate() { // Parse based from provided `uri`, for custom routing if (!empty($this->uri)) { $segments = explode('/', str_replace(Uri::base(), '', $this->uri)); $key = array_search(':page', $segments); // only find current_page if specifically set to null, otherwise assume current_page is provided if (null === $this->current_page) { if (false !== $key) { $this->uri_segment = intval($key) + 1; } $this->current_page = (int) Uri::segment($this->uri_segment); } // make sure it's an integer $this->current_page = (int) $this->current_page; } else { // URI is not given, we need to automatically detect request URI $get = Input::get(null, array()); $segments = \Uri::segments(); // use $_GET if uri_segment is specifically set to null if (null === $this->uri_segment) { if (!isset($get['page'])) { $get['page'] = 1; } $this->current_page = (int) $get['page']; $get['page'] = ':page'; } else { // start URI detection $key = $this->uri_segment - 1; // @todo it's should basically be the same. if (isset($segments[$key])) { $this->current_page = (int) $segments[$key]; } else { $this->current_page = (int) Uri::segment($this->uri_segment); } // get the route translation, as comparison to current URI segment $translation = explode('/', \Request::active()->route->translation); // we need to merge translation when Uri::segments is not enough if ($key >= count($segments)) { foreach ($translation as $seg_id => $seg_value) { if (!isset($segments[$seg_id])) { $segments[$seg_id] = $seg_value; } } } // add in action index when not available if (null === \Request::active()->route->action and count($translation) <= count($segments)) { $segments[$key - 1] = 'index'; } $segments[$key] = ':page'; } // we should add in all $_GET (useful for listing with filters) if (!empty($get)) { $get = Uri::build_get_query($get); $get = str_replace('page=%3Apage', 'page=:page', $get); } else { $get = ''; } // generate an formatted uri with :page $this->uri = implode('/', $segments) . $get; } }
/** * Add variables through method and after() and create template as a string */ public function render() { if (class_exists('Request', false)) { $current_request = \Request::active(); \Request::active($this->_active_request); } $this->{$this->_method}(); $this->after(); $return = $this->_view->render(); if (class_exists('Request', false)) { \Request::active($current_request); } return $return; }
/** * Unauthorized an action, this should be called from within a controller (included in all Hybrid\Controller classes). * * @access public * @param string $resource A string of resource name * @param bool $rest Boolean value to define weither it's a restful call or a normal http call * @return Closure * @throws AclException */ public function unauthorized($resource, $rest = false) { Lang::load('autho', 'autho'); $action = array_key_exists($resource, $this->actions) ? $this->actions[$resource] : null; $set_content_type = true; $response = Response::forge(Lang::get('autho.unauthorized', array(), 'Unauthorized'), 401); // run the callback action if ($action instanceof Closure and true !== $rest) { $callback = $action(); if ($callback instanceof Response) { $response = $callback; } } else { if ($rest === true) { if (true === \Request::is_hmvc()) { $set_content_type = false; } } else { throw new HttpNotFoundException(); } } Event::shutdown(); $response->send($set_content_type); }
/** * Execute the Rest request and return the output * * @access public * @return object */ public function execute() { if (empty($this->data)) { $this->http_status = 404; } $pattern = static::$pattern; $resource = \Request::active()->action; $format = $this->rest_format; $response = new stdClass(); $response->status = $this->http_status; // Check if a file extension is used if (preg_match($pattern, $resource, $matches)) { // Remove the extension from arguments too $resource = preg_replace($pattern, '', $resource); $format = $matches[1]; } if (null === $format) { // Which format should the data be returned in? $format = $this->detect_format(); } $response->format = $format; // If the format method exists, call and return the output in that format if (method_exists('\\Format', 'to_' . $format)) { $response->body = Format::forge($this->data)->{'to_' . $format}(); } else { $response->body = (string) $this->data; } return $response; }
/** * Check for maintenance mode * * @static * @access protected * @throws \FuelException */ protected static function maintenance_mode() { // This ensures that show_404 is only called once. static $call_count = 0; $call_count++; if ($call_count > 1) { throw new FuelException('It appears your _maintenance_mode_ route is incorrect. Multiple Recursion has happened.'); } if (Config::get('routes._maintenance_mode_') === null) { throw new FuelException('It appears your _maintenance_mode_ route is null.'); } else { $request = \Request::forge(Config::get('routes._maintenance_mode_'))->execute(); $response = $request->response(); $response->send(true); Event::shutdown(); exit; } }
<?php set_time_limit(0); error_reporting(E_ALL ^ E_NOTICE); require_once 'vendor/autoload.php'; echo '<pre>'; var_dump(\Hybrid\Request::current()); echo '</pre>';