Пример #1
0
 /**
  * Construct the session handler
  * Fetch data from request headers and authenticate the user
  */
 public function __construct()
 {
     $config = Application::get_instance()->get_config();
     if (!is_null($config->get('runtime', 'token_lifespan'))) {
         $this->token_lifespan = (int) $config->get('runtime', 'token_lifespan');
     }
     $request = Request::get_instance();
     if (isset($request->get_request_headers()['Authorization'])) {
         $authorization_string = $request->get_request_headers()['Authorization'];
         $authorization_array = explode(':', $authorization_string);
         $name = $authorization_array[0];
         $token = $authorization_array[1];
         $referer = isset($request->server()['REMOTE_ADDR']) ? $request->server()['REMOTE_ADDR'] : '';
         $agent = isset($request->server()['HTTP_USER_AGENT']) ? $request->server()['HTTP_USER_AGENT'] : '';
         $token_id = Apine\User\Factory\UserTokenFactory::authentication($name, $token, $this->token_lifespan);
         $token = Apine\User\Factory\UserTokenFactory::create_by_id($token_id);
         if ($token_id && $token->get_origin() == $referer . $agent) {
             $this->logged_in = true;
             $this->token = $token;
             $this->session_type = $this->token->get_user()->get_type();
             $this->token->set_last_access_date(date('d M Y H:i:s', time() + $this->token_lifespan));
             $this->token->save();
         }
     } else {
         if (isset($_COOKIE['apine_session'])) {
             $session = new WebSession();
             $data = $session->data();
             if ($data != null) {
                 $user_id = $data->get_var('apine_user_id');
                 if ($user_id != null) {
                     $user = UserFactory::create_by_id($user_id);
                     $token = new UserToken();
                     $token->set_user($user);
                     $this->logged_in = true;
                     $this->token = $token;
                     $this->session_type = $data->get_var('apine_user_type');
                     $this->token->set_last_access_date(date('d M Y H:i:s', time() + $this->token_lifespan));
                 }
             }
         }
     }
 }
Пример #2
0
 /**
  *
  * @see ApineEntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->token = $this->_get_field('token');
         $this->origin = $this->_get_field('origin');
         $this->creation_date = $this->_get_field('creation_date');
         $this->last_access_date = $this->_get_field('last_access_date');
         $this->disabled = (bool) $this->_get_field('disabled');
         $this->loaded = 1;
     }
 }
Пример #3
0
 /**
  * @see Entity\EntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->name = $this->_get_field('name');
         if (@unserialize($this->_get_field('value')) !== false) {
             $this->value = @unserialize($this->_get_field('value'));
         } else {
             $this->value = $this->_get_field('value');
         }
     }
 }
Пример #4
0
 /**
  *
  * @see ApineEntityInterface::load()
  */
 public function load()
 {
     if (!is_null($this->id)) {
         $this->user = Factory\UserFactory::create_by_id($this->_get_field('user_id'));
         $this->token = $this->_get_field('token');
         $this->creation_date = $this->_get_field('creation_date');
         $this->loaded = 1;
     }
 }
Пример #5
0
 /**
  * Get logged in user
  * 
  * @return Apine\User\User
  */
 public function get_user()
 {
     if ($this->is_logged_in()) {
         if (is_null($this->user)) {
             $this->user = UserFactory::create_by_id($this->user_id);
         }
     }
     return $this->user;
 }