Skip to content

Instantly share code, notes, and snippets.

@netcoop
Created April 14, 2014 10:12
Show Gist options
  • Save netcoop/10634785 to your computer and use it in GitHub Desktop.
Save netcoop/10634785 to your computer and use it in GitHub Desktop.
// file hooks/class.tx_felogin_kill_other_sessions_hook.php
<?php
require_once(PATH_tslib . 'class.tslib_pibase.php');
class tx_felogin_kill_other_sessions_hook extends tslib_pibase {
var $prefixId = 'tx_felogin_kill_other_sessions_hook';
var $scriptRelPath = 'hooks/class.tx_felogin_kill_other_sessions_hook.php';
var $extKey = 'felogin_kill_other_sessions';
/**
* Set Login log in the database when certain conditions are meet.
*
* @param array $pObj containing parameters of hooked object!
*/
function killOtherSessions(&$pObj){
$pObj = $pObj['pObj'];
if ($pObj instanceof tslib_feUserAuth){
//
// If the password timestamp is zero and the kill_other_sessions post (or get)
// var is not set then update the password timstamp with the tme now.
//
if($pObj->user['ses_id'] && $pObj->user['allowmultiplesessions']!=1) {
$ses_id = $pObj->user['ses_id'];
$ses_userid = $pObj->user[$pObj->userid_column];
$GLOBALS['TYPO3_DB']->exec_DELETEquery(
'fe_sessions',
'ses_userid = "' . $ses_userid . '" ' .
' AND ses_id != "' . $ses_id . '"');
}
}
}
}
if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/felogin_kill_other_sessions/hooks/class.tx_felogin_kill_other_sessions_hook.php'])) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/felogin_kill_other_sessions/hooks/class.tx_felogin_kill_other_sessions_hook.php']);
}
?>
// ext_localconf.php:
<?php
$TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postUserLookUp']['tx_felogin_kill_other_sessions'] = 'EXT:' . $_EXTKEY . '/hooks/class.tx_felogin_kill_other_sessions_hook.php:tx_felogin_kill_other_sessions_hook->killOtherSessions';
?>
// ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
$feusersTempColumns = array (
'allowmultiplesessions' => array (
'exclude' => 1,
'label' => 'Sta meerdere gelijktijdige login-sessies toe',
'config' => Array (
'type' => 'check',
'default' => '0'
)
),
);
t3lib_div::loadTCA('fe_users');
t3lib_extMgm::addTCAcolumns('fe_users',$feusersTempColumns, 1);
t3lib_extMgm::addToAllTCAtypes('fe_users', 'allowmultiplesessions', '', 'after:endtime');
?>
// ext_tables.sql
CREATE TABLE fe_users (
allowmultiplesessions tinyint(4) DEFAULT '0' NOT NULL
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment