Hi,
Does anyone know how to log out a user who is inactive, for say 1 hour? This is not just for the CMS, but the frontend too.
Cheers,
Josh
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Hi,
Does anyone know how to log out a user who is inactive, for say 1 hour? This is not just for the CMS, but the frontend too.
Cheers,
Josh
Have come up with this solution, seems to work well.
In your Page.php Page_Controller class, set up an init function:
function init() {
parent:: init();
self::logoutInactiveUser();
}
then put this below the init function:
function logoutInactiveUser() {
$inactivityLimit = 30; // in Minutes
$inactivityLimit = $inactivityLimit * 60; // Converted to seconds
$sessionStart = Session::get('session_start_time');
if (isset($sessionStart)){
$elapsed_time = time() - Session::get('session_start_time');
if ($elapsed_time >= $inactivityLimit) {
$member = Member::currentUser();
if($member) $member->logOut();
Session::clear_all();
Director::redirect(Director::baseURL() . 'Security/login');
}
}
Session::set('session_start_time', time());
}