Created
June 1, 2015 08:51
-
-
Save jawdatls/c82312ab0c6bdb62598e to your computer and use it in GitHub Desktop.
run some script when session end in yii1.
From http://stackoverflow.com/questions/30372786/run-some-script-when-session-end-in-yii-1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
/* configuration */ | |
var count = <?php echo Yii::app()->session->getTimeout(); ?>; //session | |
var countdown = 60; //warning 60 seconds | |
var idle = 10; //warning when idle 10 seconds | |
var urluser = <?php echo "'".Yii::app()->createUrl('site/lock', array('id'=>Yii::app()->user->id))."'"; ?>; | |
var idlecountdown = countdown; | |
var idletime = idle; | |
var show = true; | |
var counter = setInterval(timer, 1000); //1000 will run it every 1 second | |
function timer(){ | |
count = count-1; idletime = idletime-1; | |
if (count <= 0 ){ | |
clearInterval(counter); | |
// counter ended, go to the lockscreen | |
window.location.href = urluser; | |
return; | |
} | |
if (count <= countdown || idletime <= 0){ | |
count = count<=countdown?count:countdown; | |
// show warning | |
if(show){ | |
document.getElementById('tombolmodal').click(); | |
show = false; | |
} | |
document.getElementById('sisadetik').innerHTML = count; | |
} | |
window.onmousemove = function(){ idletime=idle }; | |
window.onclick = function(){ idletime=idle }; | |
window.onmousedown = function(){ idletime=idle }; | |
window.onscroll = function(){ idletime=idle }; | |
window.onkeypress = function(){ idletime=idle }; | |
// when button stay signin cliked | |
document.getElementById('staysignin').onclick = function() { | |
// access properties using this keyword | |
if ( this.click ) { | |
count = <?php echo Yii::app()->session->getTimeout(); ?>; | |
show = true; | |
idletime = idle; | |
} | |
}; | |
document.getElementById('forcelogout').onclick = function() { | |
// access properties using this keyword | |
if ( this.click ) { | |
window.location.href = urluser; | |
return; | |
} | |
}; | |
} | |
</script> | |
<!-- design of modal --> | |
<button id='tombolmodal' style="display:none" type="button" class="btn btn-info btn-lg" data-backdrop="static" data-keyboard="false" data-toggle="modal" data-target="#myModal">Open Large Modal</button> | |
<div class="modal fade" id="myModal" role="dialog"> | |
<div class="modal-dialog modal-sm"> | |
<div class="modal-content panel-danger"> | |
<div class="modal-header panel-heading" style="border-radius: inherit;"> | |
<h4 class="modal-title"><span class="glyphicon glyphicon-warning-sign"></span> | |
ATTENTION!</h4> | |
</div> | |
<div class="modal-body text-center"> | |
<h3 class="text-danger"> | |
It seems you are in inactive | |
</h3> | |
<p> | |
<b><span id="sisadetik"></span> seconds</b> left to logout your account | |
</p> | |
</div> | |
<div class="modal-footer"> | |
<!-- From this line, I Used YiiBooster Extension --> | |
<?php $this->widget('booster.widgets.TbButton', | |
array( | |
'buttonType' => 'ajaxSubmit', | |
'context' => 'primary', | |
'label' => 'Keep Sign In', | |
'url' => CController::createUrl('site/keepalive'), | |
'ajaxOptions' => array( | |
'type' => 'GET', | |
), | |
'htmlOptions' => array( | |
"data-dismiss"=>"modal", | |
'id'=>'staysignin', | |
) | |
) | |
); | |
?> | |
<?php $this->widget('booster.widgets.TbButton', | |
array( | |
'context' => 'default', | |
'label' => 'Logout', | |
'htmlOptions' => array( | |
"data-dismiss"=>"modal", | |
"id"=>"forcelogout" | |
) | |
) | |
); | |
?> | |
<!-- End of YiiBooster Extension --> | |
</div> | |
</div> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment