Ticket #354: jSession.2.patch
| File jSession.2.patch, 9.9 kB (added by Julien, 1 year ago) |
|---|
-
build/manifests/jelix-lib.mn
old new 82 82 jaclsubject.dao.xml 83 83 jaclusergroup.dao.xml 84 84 jaclgroupsofuser.dao.xml 85 jsession.dao.xml 85 86 cd lib/jelix/core-modules/jelix/install/sql 86 87 delete.mysql.sql 87 88 install_jacl.schema.mysql.sql 88 89 install_jacl.datas.mysql.sql 90 install_jsession.schema.mysql.sql 89 91 cd lib/jelix/core-modules/jelix/locales/en_US 90 92 acldb.ISO-8859-1.properties 91 93 acldb.UTF-8.properties -
build/manifests/jelix-no-opt.mn
old new 11 11 jResponse.class.php 12 12 * jSelector.class.php 13 13 * jUrl.class.php 14 jSession.class.php 14 15 15 16 cd lib/jelix/db 16 17 jDbConnection.class.php -
lib/jelix-scripts/commands/createapp.cmd.php
old new 70 70 $this->createDir(JELIX_APP_VAR_PATH.'themes/'); 71 71 $this->createDir(JELIX_APP_VAR_PATH.'themes/default/'); 72 72 $this->createDir(JELIX_APP_VAR_PATH.'uploads/'); 73 $this->createDir(JELIX_APP_VAR_PATH.'sessions/'); 73 74 $this->createDir(JELIX_APP_PATH.'modules'); 74 75 $this->createDir(JELIX_APP_PATH.'plugins'); 75 76 $this->createDir(JELIX_APP_PATH.'plugins/coord/'); -
lib/jelix-scripts/templates/var/config/defaultconfig.ini.php.tpl
old new 135 135 136 136 [acl] 137 137 driver = db 138 139 140 [sessions] 141 ; Use alternative storage engines for sessions 142 ; 143 ; usage : 144 ; 145 ; storage = "files" 146 ; files_path = "app:var/sessions/" 147 ; 148 ; or 149 ; 150 ; storage = "dao" 151 ; dao_selector = "jelix~jsession" 152 ; dao_db_profile = "" -
lib/jelix/core/jSession.class.php
old new 1 <?php 2 /** 3 * @package jelix 4 * @subpackage core 5 * @author Julien Issler 6 * @contributor 7 * @copyright 2007 Julien Issler 8 * @link http://www.jelix.org 9 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 */ 11 12 /** 13 * session management class of the jelix core 14 * 15 * @package jelix 16 * @subpackage core 17 */ 18 class jSession { 19 20 protected static $_params; 21 22 public static function start(){ 23 $params = $GLOBALS['gJConfig']->sessions; 24 25 if(!isset($params['storage'])){ 26 session_start(); 27 return true; 28 } 29 30 switch($params['storage']){ 31 32 case 'dao': 33 session_set_save_handler( 34 array(__CLASS__,'daoOpen'), 35 array(__CLASS__,'daoClose'), 36 array(__CLASS__,'daoRead'), 37 array(__CLASS__,'daoWrite'), 38 array(__CLASS__,'daoDestroy'), 39 array(__CLASS__,'daoGarbageCollector') 40 ); 41 self::$_params = $params; 42 break; 43 44 case 'files': 45 $path = str_replace(array('lib:','app:'), array(LIB_PATH, JELIX_APP_PATH), $params['files_path']); 46 session_save_path($path); 47 break; 48 49 default: 50 break; 51 } 52 53 session_start(); 54 return true; 55 } 56 57 58 public static function end(){ 59 session_write_close(); 60 return true; 61 } 62 63 64 protected static function _getDao(){ 65 if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 66 $dao = jDao::get(self::$_params['dao_selector'], self::$_params['dao_db_profile']); 67 } 68 else{ 69 $dao = jDao::get(self::$_params['dao_selector']); 70 } 71 return $dao; 72 } 73 74 75 public static function daoOpen ($save_path, $session_name) { 76 return true; 77 } 78 79 80 public static function daoClose() { 81 return true; 82 } 83 84 85 public static function daoRead ($id) { 86 $session = self::_getDao()->get($id); 87 88 if(!$session){ 89 return ''; 90 } 91 92 return $session->data; 93 } 94 95 96 public static function daoWrite ($id, $data) { 97 $dao = self::_getDao(); 98 99 $session = $dao->get($id); 100 if(!$session){ 101 $session = jDao::createRecord(self::$_params['dao_selector']); 102 $session->id = $id; 103 $session->data = $data; 104 $dao->insert($session); 105 } 106 else{ 107 $session->data = $data; 108 $dao->update($session); 109 } 110 111 return true; 112 } 113 114 115 public static function daoDestroy ($id) { 116 if (isset($_COOKIE[session_name()])) { 117 setcookie(session_name(), '', time()-42000, '/'); 118 } 119 120 $dao = self::_getDao()->delete($id); 121 return true; 122 } 123 124 125 public static function daoGarbageCollector ($maxlifetime) { 126 $date = new jDateTime(); 127 $date->now(); 128 $date->sub(0,0,0,0,0,$maxlifetime); 129 self::_getDao()->deleteExpired($date->toString(jDateTime::BD_DTFORMAT)); 130 return true; 131 } 132 133 } 134 ?> -
lib/jelix/core/jCoordinator.class.php
old new 86 86 $gJConfig = jConfig::load($configFile); 87 87 88 88 //make sure that the session cookie is only for the current application 89 if(!$gJConfig->s hared_session)89 if(!$gJConfig->sessions['shared_session']) 90 90 session_set_cookie_params ( 0 , $gJConfig->urlengine['basePath']); 91 91 92 92 // set Error and exception handler … … 167 167 168 168 $this->request = $request; 169 169 $this->request->init(); 170 session_start();170 jSession::start(); 171 171 172 172 $this->moduleName = $this->request->getParam('module'); 173 173 $this->actionName = $this->request->getParam('action'); … … 242 242 } 243 243 244 244 jContext::pop(); 245 jSession::end(); 245 246 } 246 247 247 248 /** -
lib/jelix/core/defaultconfig.ini.php
old new 19 19 20 20 theme = default 21 21 use_error_handler = on 22 shared_session = off23 22 23 24 24 [plugins] 25 25 26 26 [responses] … … 181 181 182 182 [acl] 183 183 driver = db 184 185 186 [sessions] 187 shared_session = off -
lib/jelix/init.php
old new 18 18 * @copyright 2007 Julien Issler 19 19 * @link http://www.copix.org 20 20 #else 21 * @contributor Loic Mathaud 21 * @contributor Loic Mathaud, Julien Issler 22 22 * @copyright 2005-2007 Jouanneau laurent 23 * @copyright 2007 Julien Issler 23 24 #endif 24 25 * @link http://www.jelix.org 25 26 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html … … 90 91 #includephp core/jResponse.class.php 91 92 #includephp core/jLocale.class.php 92 93 #includephp core/jIncluder.class.php 94 #includephp core/jSession.class.php 93 95 #ifnot ENABLE_PHP_JELIX 94 96 #includephp core/jICoordPlugin.iface.php 95 97 #endif … … 108 110 require (JELIX_LIB_CORE_PATH . 'jResponse.class.php'); 109 111 require (JELIX_LIB_CORE_PATH . 'jLocale.class.php'); 110 112 require (JELIX_LIB_CORE_PATH . 'jIncluder.class.php'); 113 require (JELIX_LIB_CORE_PATH . 'jSession.class.php'); 111 114 #ifnot ENABLE_PHP_JELIX 112 115 require (JELIX_LIB_CORE_PATH . 'jICoordPlugin.iface.php'); 113 116 #endif -
lib/jelix/core-modules/jelix/daos/jsession.dao.xml
old new 1 <?xml version="1.0" encoding="UTF-8"?> 2 <dao xmlns="http://jelix.org/ns/dao/1.0"> 3 <datasources> 4 <primarytable name="jsessions" realname="jsessions" primarykey="id" /> 5 </datasources> 6 7 <record> 8 <property name="id" fieldname="id" datatype="string"/> 9 <property name="creation" fieldname="creation" datatype="date" insertpattern="NOW()" updatepattern="" required="true"/> 10 <property name="access" fieldname="access" datatype="date" insertpattern="NOW()" updatepattern="NOW()" required="true"/> 11 <property name="data" fieldname="data" datatype="string" required="true"/> 12 </record> 13 14 <factory> 15 <method name="deleteExpired" type="delete"> 16 <parameter name="date" /> 17 <conditions> 18 <lt property="access" expr="$date" /> 19 </conditions> 20 </method> 21 </factory> 22 </dao> -
lib/jelix/core-modules/jelix/install/sql/install_jsession.schema.mysql.sql
old new 1 DROP TABLE IF EXISTS `jsessions`; 2 CREATE TABLE `jsessions` ( 3 `id` varchar(64) NOT NULL, 4 `creation` datetime NOT NULL, 5 `access` datetime NOT NULL, 6 `data` text NOT NULL, 7 PRIMARY KEY (`id`) 8 ) DEFAULT CHARSET=utf8;
