Skip to content

Commit ac82832

Browse files
committed
Use README.md for GitHub and README.rst for pypi.org
1 parent 5e8c7ec commit ac82832

File tree

3 files changed

+118
-13
lines changed

3 files changed

+118
-13
lines changed

README.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# django-auto-logout
2+
3+
[![Build Status](https://app.travis-ci.com/bugov/django-auto-logout.svg?branch=master)](https://app.travis-ci.com/bugov/django-auto-logout)
4+
5+
Auto logout a user after specific time in Django.
6+
7+
Works with
8+
- Python🐍 ≥ 3.7,
9+
- Django🌐 ≥ 3.0.
10+
11+
## ✔️ Installation
12+
13+
```bash
14+
pip install django-auto-logout
15+
```
16+
17+
Append to `settings.py` middlewares:
18+
19+
```python
20+
MIDDLEWARE = [
21+
# append after default middlewares
22+
'django_auto_logout.middleware.auto_logout',
23+
]
24+
```
25+
26+
---
27+
28+
**NOTE**
29+
30+
Make sure that the following middlewares are used before doing this:
31+
32+
- `django.contrib.sessions.middleware.SessionMiddleware`
33+
- `django.contrib.auth.middleware.AuthenticationMiddleware`
34+
- `django.contrib.messages.middleware.MessageMiddleware`
35+
36+
---
37+
38+
## 💤 Logout in case of idle
39+
40+
Logout a user if there are no requests for a long time.
41+
42+
Add to `settings.py`:
43+
44+
```python
45+
AUTO_LOGOUT = {'IDLE_TIME': 600} # logout after 10 minutes of downtime
46+
```
47+
48+
## ⌛ Limit session time
49+
50+
Logout a user after 3600 seconds (hour) from the last login.
51+
52+
Add to `settings.py`:
53+
54+
55+
```python
56+
AUTO_LOGOUT = {'SESSION_TIME': 3600}
57+
```
58+
59+
## ✉️ Show messages when logging out automatically
60+
61+
Set the message that will be displayed after the user automatically logs out of the system:
62+
63+
```python
64+
AUTO_LOGOUT = {
65+
'SESSION_TIME': 3600,
66+
'MESSAGE': 'The session has expired. Please login again to continue.',
67+
}
68+
```
69+
70+
It uses `django.contrib.messages`. Don't forget to display messages in templates:
71+
72+
```html
73+
{% for message in messages %}
74+
<div class="message {{ message.tags }}">
75+
{{ message }}
76+
</div>
77+
{% endfor %}
78+
```
79+
80+
---
81+
82+
**NOTE**
83+
84+
`messages` template variable provides by `django.contrib.messages.context_processors.messages`
85+
context processor.
86+
87+
See `TEMPLATES``OPTIONS``context_processors` in your `settings.py` file.
88+
89+
---
90+
91+
## 🌈 Combine configurations
92+
93+
You can combine previous configurations. For example, you may want to logout a user
94+
in case of downtime (5 minutes or more) and not allow working within one session
95+
for more than half an hour:
96+
97+
```python
98+
AUTO_LOGOUT = {
99+
'IDLE_TIME': 300, # 5 minutes
100+
'SESSION_TIME': 1800, # 30 minutes
101+
'MESSAGE': 'The session has expired. Please login again to continue.',
102+
}
103+
```

README.rst

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ django-auto-logout
66

77
Auto logout a user after specific time in Django.
88

9-
Works with Python🐍 ≥ 3.7, Django🌐 ≥ 3.0.
9+
Works with Python >= 3.7, Django >= 3.0.
1010

11-
✔️ Installation
12-
---------------------
11+
Installation
12+
------------
1313

1414
.. code:: bash
1515
@@ -26,14 +26,15 @@ Append to `settings` middlewares:
2626
]
2727
2828
.. note::
29+
2930
Make sure that the following middlewares are used before doing this:
3031

3132
- `django.contrib.sessions.middleware.SessionMiddleware`
3233
- `django.contrib.auth.middleware.AuthenticationMiddleware`
3334
- `django.contrib.messages.middleware.MessageMiddleware`
3435

35-
💤 Logout in case of idle
36-
-----------------------------
36+
Logout in case of idle
37+
----------------------
3738

3839
Logout a user if there are no requests for a long time.
3940

@@ -44,8 +45,8 @@ Add to `settings`:
4445
AUTO_LOGOUT = {'IDLE_TIME': 600} # logout after 10 minutes of downtime
4546
4647
47-
Limit session time
48-
------------------------
48+
Limit session time
49+
------------------
4950

5051
Logout a user after 3600 seconds (hour) from the last login.
5152

@@ -55,8 +56,8 @@ Add to `settings`:
5556
5657
AUTO_LOGOUT = {'SESSION_TIME': 3600}
5758
58-
✉️ Show messages when logging out automatically
59-
-----------------------------------------------------
59+
Show messages when logging out automatically
60+
--------------------------------------------
6061

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

@@ -78,13 +79,14 @@ It uses `django.contrib.messages`. Don't forget to display messages in templates
7879
{% endfor %}
7980

8081
.. note::
82+
8183
`messages` template variable provides by `django.contrib.messages.context_processors.messages`
8284
context processor.
8385

84-
See `TEMPLATES` `OPTIONS` `context_processors` in your `settings.py` file.
86+
See `TEMPLATES` - `OPTIONS` - `context_processors` in your `settings.py` file.
8587

86-
🌈 Combine configurations
87-
----------------------------
88+
Combine configurations
89+
----------------------
8890

8991
You can combine previous configurations. For example, you may want to logout a user
9092
in case of downtime (5 minutes or more) and not allow working within one session

django_auto_logout/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.3.1'
1+
__version__ = '0.3.2'

0 commit comments

Comments
 (0)