/**
  * Es la vista donde el usuario inicia sesion
  *
  * GET /sessions/logout
  */
 public function logout()
 {
     if (isset($_COOKIE['user_id'])) {
         $session = Session::find($_COOKIE['user_id']);
         $session->delete();
         setcookie('user_id', '', time() - 3600);
     }
     self::redirect_to('sessions/login');
 }
 function index($params){
     $now = time();
     $data = Session::find()->where(array("session_expire > '$now'"))->all();
     if(isset($params['partial'])){
         $this->render_partial('sessions',array('sessions' => $data));
     } else {
         $this->render(array('sessions' => $data));
     }
 }
Exemplo n.º 3
0
 static public function write_user_info(){
     $session_id = session_id();
     $session = Session::find($session_id);
     if($session && isset($_SESSION['userid'])){
         $session->user_id = $_SESSION['userid'];
         $session->current_url = Kernel::$request->relative_url;
         $session->current_ip = $_SERVER['REMOTE_ADDR'];
         $session->save();
     }
     return true;
 }
Exemplo n.º 4
0
 public static function write($sess_id, $data)
 {
     $s = new Session();
     $s->session_id = $sess_id;
     if ($s->find(true)) {
         $s->data = $data;
         if (isset($_SESSION['rememberMe']) && $_SESSION['rememberMe'] == true) {
             $s->remember_me = 1;
         }
         return $s->update();
     } else {
         return false;
     }
 }
Exemplo n.º 5
0
 /**
  * Write function that is called when session data is to be saved.
  *
  * @param string $sess_id The current session ID
  * @param string $data    The session data to write
  *
  * @return void
  * @access public
  */
 public static function write($sess_id, $data)
 {
     if (isset($_SESSION['no_store'])) {
         return true;
     }
     $s = new Session();
     $s->session_id = $sess_id;
     if ($s->find(true)) {
         $s->data = $data;
         return $s->update();
     } else {
         // in seconds - easier for calculating duration
         $s->last_used = time();
         // in date format - easier to read
         $s->created = date('Y-m-d h:i:s');
         $s->data = $data;
         return $s->insert();
     }
 }
Exemplo n.º 6
0
 public static function write($sess_id, $data)
 {
     $s = new Session();
     $s->session_id = $sess_id;
     if ($s->find(true)) {
         $s->data = $data;
         if (isset($_SESSION['rememberMe']) && ($_SESSION['rememberMe'] == true || $_SESSION['rememberMe'] === "true")) {
             $s->remember_me = 1;
             setcookie(session_name(), session_id(), time() + self::$rememberMeLifetime, '/');
         } else {
             $s->remember_me = 0;
             session_set_cookie_params(0);
         }
         parent::write($sess_id, $data);
         return $s->update();
     } else {
         //No session active
         return false;
     }
 }
Exemplo n.º 7
0
 static function gc($maxlifetime)
 {
     self::logdeb("garbage collection (maxlifetime = {$maxlifetime})");
     $epoch = common_sql_date(time() - $maxlifetime);
     $ids = array();
     $session = new Session();
     $session->whereAdd('modified < "' . $epoch . '"');
     $session->selectAdd();
     $session->selectAdd('id');
     $session->find();
     while ($session->fetch()) {
         $ids[] = $session->id;
     }
     $session->free();
     self::logdeb("Found " . count($ids) . " ids to delete.");
     foreach ($ids as $id) {
         self::logdeb("Destroying session '{$id}'.");
         self::destroy($id);
     }
 }
Exemplo n.º 8
0
 /**
  * Utility function that deletes the current session
  */
 private function deleteCurrentSession()
 {
     $idSession = session_id();
     $sessionTbl = new Session();
     $currentSession = $sessionTbl->find($idSession)->current();
     // Session found? Delete it
     if (is_object($currentSession)) {
         $q = "DELETE FROM Session WHERE idSession='{$idSession}'";
         $this->zmax_context->db->query($q);
     }
 }
Exemplo n.º 9
0
 static function gc($maxlifetime)
 {
     self::logdeb("garbage collection (maxlifetime = {$maxlifetime})");
     $epoch = common_sql_date(time() - $maxlifetime);
     $ids = array();
     $session = new Session();
     $session->whereAdd('modified < "' . $epoch . '"');
     $session->selectAdd();
     $session->selectAdd('id');
     $limit = common_config('sessions', 'gc_limit');
     if ($limit > 0) {
         // On large sites, too many sessions to expire
         // at once will just result in failure.
         $session->limit($limit);
     }
     $session->find();
     while ($session->fetch()) {
         $ids[] = $session->id;
     }
     $session->free();
     self::logdeb("Found " . count($ids) . " ids to delete.");
     foreach ($ids as $id) {
         self::logdeb("Destroying session '{$id}'.");
         self::destroy($id);
     }
 }
 /**
  * Check that a session is open and valid
  * @author philipperigaux
  *
  */
 function checkSession()
 {
     $sessionTble = new Session();
     $this->session = $sessionTble->find(session_id())->current();
     $this->getRequest()->setParam("requestedUrl", $this->myUrl());
     if (!is_object($this->session) or empty($this->session)) {
         return false;
     }
     if (!$this->session->isValid()) {
         return false;
     }
     // Take the user and put it in the controller and in the registry
     $user = new User();
     $this->user = $user->find($this->session->id_user)->current();
     return true;
 }
Exemplo n.º 11
0
 function UInterface()
 {
     global $configArray;
     global $timer;
     $local = $configArray['Site']['local'];
     $this->vufindTheme = $configArray['Site']['theme'];
     $this->isMobile = mobile_device_detect();
     $this->assign('isMobile', $this->isMobile ? 'true' : 'false');
     $this->assign('device', get_device_name());
     //Figure out google translate id
     if (isset($configArray['Translation']['google_translate_key']) && strlen($configArray['Translation']['google_translate_key']) > 0) {
         $this->assign('google_translate_key', $configArray['Translation']['google_translate_key']);
         $this->assign('google_included_languages', $configArray['Translation']['includedLanguages']);
     }
     $thisYear = new Date();
     $this->assign('lastYear', $thisYear->getYear() - 1);
     if (isset($_REQUEST['print'])) {
         $this->assign('print', true);
     }
     // Check to see if multiple themes were requested; if so, build an array,
     // otherwise, store a single string.
     $themeArray = explode(',', $this->vufindTheme);
     //Make sure we always fall back to the default theme so a template does not have to be overridden.
     $themeArray[] = 'default';
     if (count($themeArray) > 1) {
         $this->template_dir = array();
         foreach ($themeArray as $currentTheme) {
             $currentTheme = trim($currentTheme);
             $this->template_dir[] = "{$local}/interface/themes/{$currentTheme}";
         }
     } else {
         $this->template_dir = "{$local}/interface/themes/{$this->vufindTheme}";
     }
     $this->themes = $themeArray;
     if (isset($timer)) {
         $timer->logTime('Set theme');
     }
     // Create an MD5 hash of the theme name -- this will ensure that it's a
     // writeable directory name (since some config.ini settings may include
     // problem characters like commas or whitespace).
     $md5 = md5($this->vufindTheme);
     $this->compile_dir = "{$local}/interface/compile/{$md5}";
     if (!is_dir($this->compile_dir)) {
         if (!mkdir($this->compile_dir)) {
             echo "Could not create compile directory {$this->compile_dir}";
             die;
         }
     }
     $this->cache_dir = "{$local}/interface/cache/{$md5}";
     if (!is_dir($this->cache_dir)) {
         if (!mkdir($this->cache_dir)) {
             echo "Could not create cache directory {$this->cache_dir}";
             die;
         }
     }
     $this->plugins_dir = array('plugins', "{$local}/interface/plugins");
     $this->caching = false;
     $this->debug = true;
     $this->compile_check = true;
     unset($local);
     $this->register_block('display_if_inconsistent', 'display_if_inconsistent');
     $this->register_block('display_if_set', 'display_if_set');
     $this->register_function('translate', 'translate');
     $this->register_function('char', 'char');
     $this->assign('site', $configArray['Site']);
     $this->assign('path', $configArray['Site']['path']);
     $defaultConfig = $configArray['Site']['path'];
     $url = $_SERVER['SERVER_NAME'];
     if (isset($_SERVER['HTTPS'])) {
         $url = "https://" . $url;
     } else {
         $url = "http://" . $url;
     }
     if (strlen($configArray['Site']['path']) > 0) {
         $url .= '/' . $configArray['Site']['path'];
     }
     $this->url = $url;
     $this->assign('template_dir', $this->template_dir);
     $this->assign('url', $url);
     $this->assign('coverUrl', $configArray['Site']['coverUrl']);
     $this->assign('fullPath', str_replace('&', '&amp;', $_SERVER['REQUEST_URI']));
     $this->assign('requestHasParams', strpos($_SERVER['REQUEST_URI'], '?') > 0);
     if (isset($configArray['Site']['email'])) {
         $this->assign('supportEmail', $configArray['Site']['email']);
     }
     if (isset($configArray['Site']['libraryName'])) {
         $this->assign('consortiumName', $configArray['Site']['libraryName']);
     }
     $this->assign('libraryName', $configArray['Site']['title']);
     $this->assign('ils', $configArray['Catalog']['ils']);
     if (isset($configArray['Catalog']['url'])) {
         $this->assign('classicCatalogUrl', $configArray['Catalog']['url']);
     } else {
         if (isset($configArray['Catalog']['hipUrl'])) {
             $this->assign('classicCatalogUrl', $configArray['Catalog']['hipUrl']);
         }
     }
     $this->assign('showConvertListsFromClassic', $configArray['Catalog']['showConvertListsFromClassic']);
     $this->assign('theme', $this->vufindTheme);
     $this->assign('primaryTheme', reset($themeArray));
     $this->assign('device', get_device_name());
     $timer->logTime('Basic configuration');
     $this->assign('currentTab', 'Search');
     $this->assign('authMethod', $configArray['Authentication']['method']);
     if ($configArray['System']['debug']) {
         $this->assign('debug', true);
     }
     if ($configArray['System']['debugJs']) {
         $this->assign('debugJs', true);
     }
     if (isset($configArray['System']['debugCss']) && $configArray['System']['debugCss']) {
         $this->assign('debugCss', true);
     }
     // Detect Internet Explorer 8 to include respond.js for responsive css support
     if (isset($_SERVER['HTTP_USER_AGENT'])) {
         $ie8 = stristr($_SERVER['HTTP_USER_AGENT'], 'msie 8') || stristr($_SERVER['HTTP_USER_AGENT'], 'trident/5');
         //trident/5 should catch ie9 compability modes
         $this->assign('ie8', $ie8);
     }
     $session = new Session();
     $session->session_id = session_id();
     if ($session->find(true)) {
         $this->assign('session', session_id() . ', remember me ' . $session->remember_me);
     } else {
         $this->assign('session', session_id() . ' - not saved');
     }
 }