1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Хранение дополнительных данных в таблице сессий fix #590

This commit is contained in:
Mzhelskiy Maxim 2015-02-10 22:15:20 +07:00
parent efe731ec1b
commit 38f01da097
5 changed files with 65 additions and 5 deletions

View file

@ -612,6 +612,9 @@ class ModuleUser extends Module
}
if ($sKey = $this->Session_GetCookie('key') and is_string($sKey)) {
if ($oUser = $this->GetUserBySessionKey($sKey) and $oSession = $this->oMapper->GetSessionByKey($sKey) and $oSession->isActive()) {
/**
* Перед запуском авторизации дополнительно можно проверить user-agent'а пользователя
*/
$this->Authorization($oUser, true, $oSession->getKey());
} else {
$this->Logout();
@ -772,6 +775,7 @@ class ModuleUser extends Module
$oSession->setKey($sKey);
$oSession->setIpCreate(func_getIp());
$oSession->setDateCreate(date("Y-m-d H:i:s"));
$oSession->setExtraParam('user_agent',isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '');
}
$oSession->setUserId($oUser->getId());
$oSession->setIpLast(func_getIp());

View file

@ -97,18 +97,60 @@ class ModuleUser_EntitySession extends Entity
return $this->_getDataOne('session_date_close');
}
/**
* Возвращает дополнительные данные
*
* @return string|null
*/
public function getExtra()
{
return $this->_getDataOne('session_extra');
}
/**
* Проверяет факт активности сессии
*
* @return bool
*/
public function isActive() {
public function isActive()
{
if ($this->getDateClose()) {
return false;
}
return true;
}
/**
* Возвращает параметр по имени
*
* @param $sName
* @return null
*/
public function getExtraParam($sName)
{
if ($sExtra = $this->getExtra() and $aData = @unserialize($sExtra)) {
if (isset($aData[$sName])) {
return $aData[$sName];
}
}
return null;
}
/**
* Устанавливает параметр по имени
*
* @param $sName
* @param $mValue
*/
public function setExtraParam($sName, $mValue)
{
if (!($sExtra = $this->getExtra() and $aData = @unserialize($sExtra))) {
$aData = array();
}
$aData[$sName] = $mValue;
$this->setExtra(serialize($aData));
}
/**
* Устанавливает ключ сессии
@ -179,4 +221,14 @@ class ModuleUser_EntitySession extends Entity
{
$this->_aData['session_date_close'] = $data;
}
/**
* Устанавливает дополнительные данные
*
* @param string $data
*/
public function setExtra($data)
{
$this->_aData['session_extra'] = $data;
}
}

View file

@ -191,10 +191,11 @@ class ModuleUser_MapperUser extends Mapper
session_ip_create = ? ,
session_ip_last = ? ,
session_date_create = ? ,
session_date_last = ?
session_date_last = ? ,
session_extra = ?
";
return $this->oDb->query($sql, $oSession->getKey(), $oSession->getUserId(), $oSession->getIpCreate(),
$oSession->getIpLast(), $oSession->getDateCreate(), $oSession->getDateLast());
$oSession->getIpLast(), $oSession->getDateCreate(), $oSession->getDateLast(), $oSession->getExtra());
}
/**

View file

@ -829,4 +829,7 @@ ALTER TABLE `prefix_topic` ADD `blog_id2` INT UNSIGNED NULL DEFAULT NULL AFTER `
ALTER TABLE `prefix_topic` ADD INDEX(`blog_id2`);
ALTER TABLE `prefix_topic` ADD INDEX(`blog_id3`);
ALTER TABLE `prefix_topic` ADD INDEX(`blog_id4`);
ALTER TABLE `prefix_topic` ADD INDEX(`blog_id5`);
ALTER TABLE `prefix_topic` ADD INDEX(`blog_id5`);
-- 10.02.2015
ALTER TABLE `prefix_session` ADD `session_extra` TEXT NULL ;

@ -1 +1 @@
Subproject commit 47fab4565ac7233d2c8070aebe0a3f1ee3c27221
Subproject commit c9c28990dc657bd5e3373581a6915aa21b5f1c7e