/** * Get self instance from cache instead of initiating a new object if time * we need to use this object * * @static * @access public * @return self */ public static function __callStatic($method, array $arguments) { if (!in_array($method, array('factory', 'forge', 'instance', 'make'))) { throw new FuelException(__CLASS__ . '::' . $method . '() does not exist.'); } return Auth::make('user'); }
/** * 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'); return parent::before(); }
/** * 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 before we route to the destinated method * * @access public * @return void */ public function before() { $this->rest = Restserver::is_rest(); $this->language = Factory::get_language(); $this->user = Auth::make('user')->get(); Event::trigger('controller_before'); if (false === $this->rest) { $this->prepare_template(); } else { $this->prepare_rest(); } return parent::before(); }
/** * Determine whether authenticated user should be continue to login or register new user * * @static * @access public * @param object $strategy * @return void * @throws Auth_Strategy_Exception */ public static function login_or_register($strategy) { $token = $strategy->callback(); $user_info = static::get_user_info($strategy, $token); $user_data = array('token' => $token, 'info' => $user_info, 'provider' => $strategy->provider->name); $user_auth = Auth::make('user'); if (true === $user_auth->is_logged()) { // User already logged in $user_id = $user_auth->get('id'); $accounts = $user_auth->get('accounts'); $num_linked = count($accounts); // Allowed multiple providers, or not authed yet? if (0 === $num_linked or true === Config::get('autho.link_multiple_providers')) { try { $user_auth->link_account($user_data); Event::trigger('link_authentication', $user_data); } catch (AuthException $e) { throw new Auth_Strategy_Exception("Unable to retrieve valid user information from requested access token"); } // Attachment went ok so we'll redirect Auth::redirect('logged_in'); } else { $providers = array_keys($accounts); throw new Auth_Strategy_Exception(sprintf('This user is already linked to "%s".', $providers[0])); } } else { try { $user_auth->login_token($user_data); Event::trigger('link_authentication', $user_data); // credentials ok, go right in Auth::redirect('logged_in'); } catch (AuthException $e) { Session::set('autho', $user_data); Auth::redirect('registration'); } } }
/** * Verify whether current user has sufficient roles to access the resources based * on available type of access. * * @access public * @param mixed $resource A string of resource name * @param string $type need to be any one of deny, view, create, edit, delete or all * @return bool * @throws AclException */ public function access($resource, $type = 'view') { $types = static::$types; if (!in_array($resource, $this->resources)) { throw new AclException(__METHOD__ . ": Unable to verify unknown resource {$resource}."); } $user = Auth::make('user')->get(); $type_id = array_search($type, $types); $length = count($types); if (empty($user->roles) and in_array('guest', $this->roles)) { array_push($user->roles, 'guest'); } foreach ($user->roles as $role) { if (!isset($this->acl[$role . '/' . $resource])) { continue; } if ($this->acl[$role . '/' . $resource] == $type) { return true; } for ($i = $type_id + 1; $i < $length; $i++) { if ($this->acl[$role . '/' . $resource] == $types[$i]) { return true; } } } return false; }