@@ -50,6 +50,63 @@ or the same, but with `datetime.timedelta` (more semantically):
50
50
51
51
AUTO_LOGOUT = {' IDLE_TIME' : timedelta(minutes = 10 )}
52
52
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
+
53
110
Limit session time
54
111
------------------
55
112
@@ -67,6 +124,13 @@ or the same, but with `datetime.timedelta` (more semantically):
67
124
68
125
AUTO_LOGOUT = {' SESSION_TIME' : timedelta(hours = 1 )}
69
126
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
+
70
134
Show messages when logging out automatically
71
135
--------------------------------------------
72
136
@@ -112,4 +176,5 @@ for more than half an hour:
112
176
' IDLE_TIME' : timedelta(minutes = 5 ),
113
177
' SESSION_TIME' : timedelta(minutes = 30 ),
114
178
' MESSAGE' : ' The session has expired. Please login again to continue.' ,
179
+ ' REDIRECT_TO_LOGIN_IMMEDIATELY' : True ,
115
180
}
0 commit comments