Skip to content

Commit 898366a

Browse files
committed
issue #11. Upd readme.rst
1 parent 18fb25f commit 898366a

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

README.rst

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,63 @@ or the same, but with `datetime.timedelta` (more semantically):
5050
5151
AUTO_LOGOUT = {'IDLE_TIME': timedelta(minutes=10)}
5252
53+
The user will log out the next time the page is requested.
54+
See `REDIRECT_TO_LOGIN_IMMEDIATELY` to log out right after the idle-time has expired
55+
(and redirect to login page).
56+
57+
REDIRECT_TO_LOGIN_IMMEDIATELY after the idle-time has expired
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59+
60+
Use the `REDIRECT_TO_LOGIN_IMMEDIATELY` option
61+
if you want to redirect the user to the login page
62+
immediately after the idle-time expires:
63+
64+
.. code:: python
65+
66+
from datetime import timedelta
67+
AUTO_LOGOUT = {
68+
'IDLE_TIME': timedelta(minutes=10),
69+
'REDIRECT_TO_LOGIN_IMMEDIATELY': True,
70+
}
71+
72+
This requires a client-side script, so you should
73+
modify your `context_processors` in `settings.py`:
74+
75+
.. code:: python
76+
77+
TEMPLATES = [
78+
{
79+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
80+
'DIRS': [],
81+
'APP_DIRS': True,
82+
'OPTIONS': {
83+
'context_processors': [
84+
'django.template.context_processors.debug',
85+
'django.template.context_processors.request',
86+
'django.contrib.auth.context_processors.auth',
87+
'django.contrib.messages.context_processors.messages',
88+
# !!! Add this !!!
89+
'django_auto_logout.context_processors.auto_logout_client',
90+
],
91+
},
92+
},
93+
]
94+
95+
And add this to your templates (will add a redirect script to your html):
96+
97+
.. code:: bash
98+
99+
{{ redirect_to_login_immediately }}
100+
101+
If you want to use this in your JavaScript code, following template variables may be useful:
102+
103+
.. code:: javascript
104+
105+
var sessionEnd = {{ seconds_until_session_end }};
106+
var idleEnd = {{ seconds_until_idle_end }};
107+
108+
`REDIRECT_TO_LOGIN_IMMEDIATELY` works with `SESSION_TIME` too.
109+
53110
Limit session time
54111
------------------
55112

@@ -67,6 +124,13 @@ or the same, but with `datetime.timedelta` (more semantically):
67124
68125
AUTO_LOGOUT = {'SESSION_TIME': timedelta(hours=1)}
69126
127+
.. note::
128+
129+
See `REDIRECT_TO_LOGIN_IMMEDIATELY` option
130+
if you want to redirect user to the login page
131+
right after the idle-time has expired.
132+
133+
70134
Show messages when logging out automatically
71135
--------------------------------------------
72136

@@ -112,4 +176,5 @@ for more than half an hour:
112176
'IDLE_TIME': timedelta(minutes=5),
113177
'SESSION_TIME': timedelta(minutes=30),
114178
'MESSAGE': 'The session has expired. Please login again to continue.',
179+
'REDIRECT_TO_LOGIN_IMMEDIATELY': True,
115180
}

0 commit comments

Comments
 (0)