Esempio n. 1
0
 /**
  * SessionData class' constructor
  *
  * @param string $a_id
  *        Session Identifier
  */
 public function __construct($a_id = null)
 {
     if ($a_id != null) {
         $this->session_id = $a_id;
     } else {
         if (Cookie::get('apine_session') != null) {
             $this->session_id = Cookie::get('apine_session');
         } else {
             $this->session_id = Encryption::token();
         }
     }
     $this->_initialize('apine_sessions', $this->session_id);
 }
Esempio n. 2
0
 /**
  * Construct the session handler
  * Fetch data from PHP structures and start the PHP session
  */
 public function __construct()
 {
     $config = Application::get_instance()->get_config();
     if ($config->get('runtime', 'user_class')) {
         $user_class = $config->get('runtime', 'user_class');
         $pos_slash = strpos($user_class, '/');
         $module = substr($user_class, 0, $pos_slash);
         $class = substr($user_class, $pos_slash + 1);
         apine_load_module($module);
         if (is_a($class, 'Apine\\User\\User')) {
             $this->user_class_name = $class;
         } else {
             $this->user_class_name = 'Apine\\User\\User';
         }
     } else {
         $this->user_class_name = "Apine\\User\\User";
     }
     if (!is_null($config->get('runtime', 'session_lifespan'))) {
         $this->session_lifespan = (int) $config->get('runtime', 'session_lifespan');
     }
     if (!is_null($config->get('runtime', 'session_permanent_lifespan'))) {
         $this->session_lifespan = (int) $config->get('runtime', 'session_permanent_lifespan');
     }
     if (isset($_COOKIE['apine_session'])) {
         $token = $_COOKIE['apine_session'];
     } else {
         $token = Encryption::token();
     }
     $this->session = new SessionData($token);
     $this->php_session_id = $token;
     $delay = $this->session_lifespan;
     $this->logged_in = false;
     if ($this->session->get_var('apine_user_id') != null) {
         if ($this->session->get_var('apine_session_permanent') != null) {
             $delay = $this->session_permanent_lifespan;
         }
         if ($this->session->is_valid($delay) && UserFactory::is_id_exist($this->session->get_var('apine_user_id'))) {
             $this->logged_in = true;
             $this->user_id = $this->session->get_var('apine_user_id');
             $this->session_type = $this->session->get_var('apine_user_type');
         } else {
             $this->session->reset();
         }
     }
     $this->current_session_lifespan = $delay;
     setcookie('apine_session', $this->php_session_id, time() + $delay, '/');
 }