Ticket #354: jSession.patch
| File jSession.patch, 10.3 kB (added by Julien, 1 year ago) |
|---|
-
build/manifests/jelix-lib.mn
old new 260 260 cd lib/jelix-modules/jauth/zones 261 261 ! loginform.zone.php 262 262 263 cd lib/jelix-modules/jsession/daos 264 session.dao.xml 263 265 266 264 267 cd lib/jelix-plugins 265 268 LICENCE 266 269 INSTALL -
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 = "jsession~session" 152 ; dao_db_profile = "" -
lib/jelix-modules/jsession/daos/session.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="sessions" realname="sessions" 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()" required="true"/> 10 <property name="access" fieldname="access" datatype="date" updatepattern="NOW()" insertpattern="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/db/jDbConnection.class.php
old new 68 68 function __destruct(){ 69 69 if($this->_connection !== null){ 70 70 $this->_disconnect (); 71 $this->_connection = null; 71 72 } 72 73 } 73 74 … … 233 234 */ 234 235 abstract protected function _connect (); 235 236 237 236 238 /** 239 * Do a reconnection if connection is down 240 * 241 * @author Julien Issler 242 */ 243 public function reconnect(){ 244 if(!$this->_connection){ 245 $this->_connection = $this->_connect(); 246 } 247 } 248 249 250 /** 237 251 * do a disconnection 238 252 * (no need to do a test on the connection id) 239 253 */ -
lib/jelix/core/jCoordinator.class.php
old new 3 3 * @package jelix 4 4 * @subpackage core 5 5 * @author Laurent Jouanneau 6 * @contributor 6 * @contributor Julien Issler 7 7 * @copyright 2005-2006 laurent Jouanneau 8 * @copyright 2007 Julien Issler 8 9 * @link http://www.jelix.org 9 10 * @licence GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html 10 11 */ … … 84 85 } 85 86 // load configuration data 86 87 $gJConfig = jConfig::load($configFile); 88 89 // reference the config file in jSession, because gJConfig no longer exists when the session data is written, and we need it for Dao storage 90 jSession::$jConfigFile = $configFile; 87 91 88 92 //make sure that the session cookie is only for the current application 89 93 if(!$gJConfig->shared_session) … … 167 171 168 172 $this->request = $request; 169 173 $this->request->init(); 170 session_start();174 jSession::start(); 171 175 172 176 $this->moduleName = $this->request->getParam('module'); 173 177 $this->actionName = $this->request->getParam('action'); -
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 21 protected static $_params; 22 public static $jConfigFile; 23 24 public static function start(){ 25 global $gJConfig; 26 27 if(!isset($gJConfig->sessions)){ 28 session_start(); 29 return true; 30 } 31 32 self::$_params = $gJConfig->sessions; 33 34 if(!isset(self::$_params['storage'])){ 35 session_start(); 36 return true; 37 } 38 39 switch(self::$_params['storage']){ 40 41 case 'dao': 42 43 session_set_save_handler( 44 array(__CLASS__,'dao_open'), 45 array(__CLASS__,'dao_close'), 46 array(__CLASS__,'dao_read'), 47 array(__CLASS__,'dao_write'), 48 array(__CLASS__,'dao_destroy'), 49 array(__CLASS__,'dao_gc') 50 ); 51 break; 52 53 case 'files': 54 $path = str_replace(array('lib:','app:'), array(LIB_PATH, JELIX_APP_PATH), self::$_params['files_path']); 55 session_save_path($path); 56 break; 57 58 default: 59 break; 60 } 61 62 session_start(); 63 return true; 64 } 65 66 67 protected static function _getDao(){ 68 69 if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 70 $dao = jDao::get(self::$_params['dao_selector'], self::$_params['dao_db_profile']); 71 } 72 else{ 73 $dao = jDao::get(self::$_params['dao_selector']); 74 } 75 76 return $dao; 77 78 } 79 80 public static function dao_open ($save_path, $session_name) { 81 return true; 82 } 83 84 public static function dao_close() { 85 return true; 86 } 87 88 public static function dao_read ($id) { 89 $dao = self::_getDao(); 90 91 $session = $dao->get($id); 92 93 if(!$session){ 94 return ''; 95 } 96 97 return $session->data; 98 } 99 100 public static function dao_write ($id, $data) { 101 global $gJConfig; 102 103 $gJConfig = jConfig::load(self::$jConfigFile); 104 105 if(isset(self::$_params['dao_db_profile']) && self::$_params['dao_db_profile']){ 106 $cnx = jDb::getConnection(self::$_params['dao_db_profile']); 107 } 108 else{ 109 $cnx = jDb::getConnection(); 110 } 111 $cnx->reconnect(); 112 113 $dao = self::_getDao(); 114 115 $session = $dao->get($id); 116 if(!$session){ 117 $session = jDao::createRecord(self::$_params['dao_selector']); 118 $session->id = $id; 119 $session->data = $data; 120 $dao->insert($session); 121 } 122 else{ 123 $session->data = $data; 124 $dao->update($session); 125 } 126 127 return true; 128 129 } 130 131 public static function dao_destroy ($id) { 132 133 134 if (isset($_COOKIE[session_name()])) { 135 setcookie(session_name(), '', time()-42000, '/'); 136 } 137 $dao = self::_getDao(); 138 $dao->delete($id); 139 return true; 140 } 141 142 public static function dao_gc ($maxlifetime) { 143 144 145 $date = new jDateTime(); 146 $date->now(); 147 $date->sub(0,0,0,0,0,$maxlifetime); 148 $dao = self::_getDao(); 149 $dao->deleteExpired($date->toString(jDateTime::BD_DTFORMAT)); 150 151 return true; 152 } 153 154 155 } -
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
