Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
 /**
  * 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();
 }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 4
0
 /**
  * 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');
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * Link user account with external provider
  *
  * @access  public
  * @param   array   $user_data
  * @return  bool
  */
 public function link_account($user_data)
 {
     if (true !== Auth::link_account($this->provider->data['id'], $user_data)) {
         return false;
     }
     extract($user_data);
     $this->provider->data['accounts'][$provider] = array('uid' => $info['uid'], 'access_token' => isset($token->access_token) ? $token->access_token : '', 'secret' => isset($token->secret) ? $token->secret : '');
     return true;
 }
Exemplo n.º 7
0
 /**
  * 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;
 }