Просмотр исходного кода

Ticket #3415: Sessions - restore an old session when member returns to a site

Alexander 5 лет назад
Родитель
Сommit
7cf5d28afd
2 измененных файлов с 15 добавлено и 1 удалено
  1. 10 1
      inc/classes/BxDolSession.php
  2. 5 0
      inc/classes/BxDolSessionQuery.php

+ 10 - 1
inc/classes/BxDolSession.php

@@ -80,7 +80,16 @@ class BxDolSession extends BxDolFactory implements iBxDolSingleton
 		if($this->bAutoLogout && isLogged())
 			bx_logout();
 
-        $this->sId = genRndPwd(32, true);
+		// try to restore user's old session
+		if (isLogged()) {
+		    $this->sId = $this->oDb->getOldSession(getLoggedId());
+		    if ($this->sId)
+		        $this->exists($this->sId); // it exists for sure but required for initializing some data there
+        }
+
+		// if an old session has not been found then generate a new one
+		if (!$this->sId)
+            $this->sId = genRndPwd(32, true);
 
         $aUrl = parse_url(BX_DOL_URL_ROOT);
         $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';

+ 5 - 0
inc/classes/BxDolSessionQuery.php

@@ -65,6 +65,11 @@ class BxDolSessionQuery extends BxDolDb
             $this->query("OPTIMIZE TABLE `" . $this->sTable . "`");
         return $iRet;
     }
+    function getOldSession($iUserId) {
+        $sSql = $this->prepare("SELECT `id` FROM `" . $this->sTable . "` WHERE `user_id`=? LIMIT 1", $iUserId);
+        $sSession = $this->getOne($sSql);
+        return !empty($sSession) ? $sSession : false;
+    }
 }
 
 /** @} */