Beispiel #1
0
 /**
  * Set the token user
  * 
  * @param <Apine\User\User|integer> $a_user
  * @return Apine\User\User|integer>
  */
 public function set_user($a_user)
 {
     if ($this->loaded == 0) {
         $this->load();
     }
     if (is_numeric($a_user) && Factory\UserFactory::is_id_exist($a_user)) {
         $this->user = Factory\UserFactory::create_by_id($a_user);
     } else {
         if (is_a($a_user, 'Apine\\User\\User')) {
             $this->user = $a_user;
         } else {
             return false;
         }
     }
     $this->_set_field('user_id', $this->user->get_id());
     return $this->user;
 }
 /**
  * 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, '/');
 }