public function callback() { // Load the provider $this->provider = Provider::forge($this->provider, $this->config); $error = Input::get('error'); if (null !== $error) { throw new Auth_Strategy_Exception(ucfirst($this->provider->name) . " Error: " . $error); } $code = Input::get('code'); if (null === $code or empty($code)) { // Send the user back to the beginning throw new Auth_Strategy_Exception('invalid token after coming back to site'); } try { return $this->provider->access($code); } catch (Exception $e) { throw new Auth_Strategy_Exception('That didnt work: ' . $e); } }
public function callback() { // Create an consumer from the config $this->consumer = Consumer::forge($this->config); // Load the provider $this->provider = Provider::forge($this->provider); if ($token = Cookie::get('oauth_token')) { // Get the token from storage $this->token = unserialize(base64_decode($token)); } if ($this->token and $this->token->access_token !== Input::get_post('oauth_token')) { // Delete the token, it is not valid Cookie::delete('oauth_token'); // Send the user back to the beginning throw new Auth_Strategy_Exception('invalid token after coming back to site'); } // Get the verifier $verifier = Input::get_post('oauth_verifier'); // Store the verifier in the token $this->token->verifier($verifier); // Exchange the request token for an access token return $this->provider->access_token($this->consumer, $this->token); }
/** * Requests are not made to methods directly The request will be for an "object". * this simply maps the object and method to the correct Controller method. * * @access public * @param Request $resource * @param array $arguments * @return void */ public function router($resource, $arguments) { $pattern = Restserver::$pattern; // Remove the extension from arguments too $resource = preg_replace($pattern, '', $resource); // If they call user, go to $this->post_user(); $controller_method = strtolower(Input::method()) . '_' . $resource; if (method_exists($this, $controller_method) and true === $this->rest) { return call_user_func(array($this, $controller_method)); } elseif (method_exists($this, 'action_' . $resource)) { if (true === $this->rest) { $this->response->status = $this->no_method_status; return; } return call_user_func_array(array($this, 'action_' . $resource), $arguments); } else { if (true === $this->rest) { $this->response->status = $this->no_method_status; return; } else { throw new HttpNotFoundException(); } } }
/** * 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; } }
/** * This executes the request and sets the output to be used later. * Cleaning up our request after executing \Request::execute() * * Usage: * * <code>$exec = \Hybrid\Request::connect('PUT controller/method?hello=world')->execute(); * \Debug::dump($exec);</code> * * @param array|null $method_params An array of parameters to pass to the method being executed * @return object containing $data and HTTP Response $status * @see \Request::execute() */ public function execute($method_params = null) { // Since this just a imitation of curl request, \Hybrid\Input need to know the // request method and data available in the connection. Input::connect($this->request_method, $this->request_data); $execute = parent::execute($method_params); // We need to clean-up any request object transfered to \Hybrid\Input so that // any following request to \Hybrid\Input will redirected to \Fuel\Core\Input Input::disconnect(); $this->request_method = ''; $this->request_data = array(); return $execute; }
/** * Build query string * * @static * @access public * @param mixed $values * @return string */ public static function build_get_query($values) { $dataset = array(); $check_get_input = function ($value, &$dataset) { $data = \Hybrid\Input::get($value); if (empty($data)) { return false; } else { array_push($dataset, sprintf('%s=%s', $value, $data)); return; } }; if (is_array($values)) { foreach ($values as $value) { $check_get_input($value, $dataset); } } else { $check_get_input($values, $dataset); } return '?' . implode('&', $dataset); }
/** * Detect language(s) should be used to output the data * * @static * @access protected * @return string */ protected static function detect_lang() { if (!($lang = Input::server('HTTP_ACCEPT_LANGUAGE'))) { return null; } // They might have sent a few, make it an array if (strpos($lang, ',') !== false) { $langs = explode(',', $lang); $return_langs = array(); foreach ($langs as $lang) { // Remove weight and strip space list($lang) = explode(';', $lang); $return_langs[] = trim($lang); } return $return_langs; } // Nope, just return the string return $lang; }
/** * Dynamically load profiling using $_GET['profiler'] = 1; * * @static * @access protected * @return void */ protected static function profiling() { $session = Session::instance(); $profiler = $session->get('_profiler', Config::get('profiling', false)); if (null !== ($input = Input::get('profiler'))) { $profiler = (int) $input === 1 ? true : false; } switch ($profiler) { case 1: Fuel::$profiling = true; Profiler::init(); break; } $session->set('_profiler', $profiler); }
/** * Fetch user information (not using Model) * * @access protected * @param array $result * @return bool */ protected function fetch_user($result) { if (null === $result or $result->count() < 1) { return $this->reset(); } $user = $result->current(); if (!in_array($user->status, $this->allowed_status)) { // only verified user can login to this application return $this->reset(); } // we validate the hash to add security to this application $hash = $user->user_name . $user->password_token; if ($this->verify_user_agent) { $hash .= Input::user_agent(); } // validate our hash data if (null !== $this->data['_hash'] and $this->data['_hash'] !== Auth::create_hash($hash)) { return $this->reset(); } // user_id property wouldn't be available if we don't use meta or auth if (!$this->use_meta and !$this->use_auth) { $this->data['id'] = $user->id; } else { $user_id_field = Inflector::singularize($this->tables['user']) . '_id'; $this->data['id'] = $user->{$user_id_field}; } $user_name = Arr::get($this->aliases, 'user_name', 'user_name'); $email = Arr::get($this->aliases, 'email', 'email'); $this->data[$user_name] = $user->{$user_name}; $this->data[$email] = $user->{$email}; $this->data['password'] = $user->password_token; foreach ($this->optionals as $property) { if (!property_exists($user, $property)) { continue; } $this->data[$property] = $user->{$property}; } $this->cached_db_result = $result; }
/** * Requests are not made to methods directly The request will be for an "object". * this simply maps the object and method to the correct Controller method. * * @param Request $resource * @param array $arguments */ public function router($resource, $arguments) { $pattern = \Hybrid\Restful::$pattern; // Remove the extension from arguments too $resource = preg_replace($pattern, '', $resource); // If they call user, go to $this->post_user(); $controller_method = strtolower(\Hybrid\Input::method()) . '_' . $resource; if (method_exists($this, $controller_method)) { call_user_func(array($this, $controller_method)); } else { $this->response->status = 404; return; } }