Skip to content

Commit 5f61d98

Browse files
committed
issue #11. Add documentation for REDIRECT_TO_LOGIN_PAGE
1 parent 4e2b4bb commit 5f61d98

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
__pycache__
55
*.egg-info
66
*.sqlite3
7+
*.log
78
venv
89
htmlcov
910
build

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,56 @@ from datetime import timedelta
5353
AUTO_LOGOUT = {'IDLE_TIME': timedelta(minutes=10)}
5454
```
5555

56+
The user will log out the next time the page is requested.
57+
See `REDIRECT_TO_LOGIN_PAGE` to log out right after the idle-time has expired
58+
(and redirect to login page).
59+
60+
### 🔄 `REDIRECT_TO_LOGIN_PAGE` right after the idle-time has expired
61+
62+
Use the `REDIRECT_TO_LOGIN_PAGE` option
63+
if you want to redirect the user to the login page
64+
immediately after the idle-time expires:
65+
66+
```python
67+
from datetime import timedelta
68+
69+
AUTO_LOGOUT = {
70+
'IDLE_TIME': timedelta(minutes=10),
71+
'REDIRECT_TO_LOGIN_PAGE': True,
72+
}
73+
```
74+
75+
This requires a client-side script, so you should
76+
modify your `context_processors` in `settings.py`:
77+
78+
```python
79+
TEMPLATES = [
80+
{
81+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
82+
'DIRS': [],
83+
'APP_DIRS': True,
84+
'OPTIONS': {
85+
'context_processors': [
86+
'django.template.context_processors.debug',
87+
'django.template.context_processors.request',
88+
'django.contrib.auth.context_processors.auth',
89+
'django.contrib.messages.context_processors.messages',
90+
# ↓↓↓ Add this ↓↓↓
91+
'django_auto_logout.context_processors.auto_logout_client',
92+
],
93+
},
94+
},
95+
]
96+
```
97+
98+
And add it to your templates (will add a redirect script to your html):
99+
100+
```
101+
{{ redirect_to_login_page }}
102+
```
103+
104+
It also works with `SESSION_TIME`.
105+
56106
## ⌛ Limit session time
57107

58108
Logout a user after 3600 seconds (hour) from the last login.
@@ -71,6 +121,16 @@ from datetime import timedelta
71121
AUTO_LOGOUT = {'SESSION_TIME': timedelta(hours=1)}
72122
```
73123

124+
---
125+
126+
**NOTE**
127+
128+
See `REDIRECT_TO_LOGIN_PAGE` option
129+
if you want to redirect user to the login page
130+
right after the idle-time has expired.
131+
132+
---
133+
74134
## ✉️ Show messages when logging out automatically
75135

76136
Set the message that will be displayed after the user automatically logs out of the system:

0 commit comments

Comments
 (0)