A little javascript and middleware work together to ensure that the user was active during the past X minutes in any tab he has open. Otherwise, display a warning leaving a couple of minutes to show any kind of activity like moving the mouse. Otherwise, logout the user.
This adds a counter to count down the number of seconds remaining until expiration if counterElementID is set, e.g.:
<h3>{% trans 'Your session is about to expire in' %} <span id="in_seconds"></span> {% trans 'seconds' %}</h3>
<script type="text/javascript">
var sessionSecurity = new yourlabs.SessionSecurity({
pingUrl: '{% url 'session_security_ping' %}',
warnAfter: {{ request|warn_after|unlocalize }},
expireAfter: {{ request|expire_after|unlocalize }},
confirmFormDiscard: "{% trans 'You have unsaved changes in a form of this page.' %}",
counterElementID: "in_seconds"
});
</script>
This adds a counter to count down the number of seconds remaining until expiration if counterElementID is set, e.g.: