Skip to content

Commit

Permalink
Use README.md for GitHub and README.rst for pypi.org
Browse files Browse the repository at this point in the history
  • Loading branch information
bugov committed Oct 13, 2021
1 parent 5e8c7ec commit ac82832
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 13 deletions.
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# django-auto-logout

[![Build Status](https://app.travis-ci.com/bugov/django-auto-logout.svg?branch=master)](https://app.travis-ci.com/bugov/django-auto-logout)

Auto logout a user after specific time in Django.

Works with
- Python🐍 ≥ 3.7,
- Django🌐 ≥ 3.0.

## ✔️ Installation

```bash
pip install django-auto-logout
```

Append to `settings.py` middlewares:

```python
MIDDLEWARE = [
# append after default middlewares
'django_auto_logout.middleware.auto_logout',
]
```

---

**NOTE**

Make sure that the following middlewares are used before doing this:

- `django.contrib.sessions.middleware.SessionMiddleware`
- `django.contrib.auth.middleware.AuthenticationMiddleware`
- `django.contrib.messages.middleware.MessageMiddleware`

---

## 💤 Logout in case of idle

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

Add to `settings.py`:

```python
AUTO_LOGOUT = {'IDLE_TIME': 600} # logout after 10 minutes of downtime
```

## ⌛ Limit session time

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

Add to `settings.py`:


```python
AUTO_LOGOUT = {'SESSION_TIME': 3600}
```

## ✉️ Show messages when logging out automatically

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

```python
AUTO_LOGOUT = {
'SESSION_TIME': 3600,
'MESSAGE': 'The session has expired. Please login again to continue.',
}
```

It uses `django.contrib.messages`. Don't forget to display messages in templates:

```html
{% for message in messages %}
<div class="message {{ message.tags }}">
{{ message }}
</div>
{% endfor %}
```

---

**NOTE**

`messages` template variable provides by `django.contrib.messages.context_processors.messages`
context processor.

See `TEMPLATES``OPTIONS``context_processors` in your `settings.py` file.

---

## 🌈 Combine configurations

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

```python
AUTO_LOGOUT = {
'IDLE_TIME': 300, # 5 minutes
'SESSION_TIME': 1800, # 30 minutes
'MESSAGE': 'The session has expired. Please login again to continue.',
}
```
26 changes: 14 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ django-auto-logout

Auto logout a user after specific time in Django.

Works with Python🐍 ≥ 3.7, Django🌐 ≥ 3.0.
Works with Python >= 3.7, Django >= 3.0.

✔️ Installation
---------------------
Installation
------------

.. code:: bash
Expand All @@ -26,14 +26,15 @@ Append to `settings` middlewares:
]
.. note::

Make sure that the following middlewares are used before doing this:

- `django.contrib.sessions.middleware.SessionMiddleware`
- `django.contrib.auth.middleware.AuthenticationMiddleware`
- `django.contrib.messages.middleware.MessageMiddleware`

💤 Logout in case of idle
-----------------------------
Logout in case of idle
----------------------

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

Expand All @@ -44,8 +45,8 @@ Add to `settings`:
AUTO_LOGOUT = {'IDLE_TIME': 600} # logout after 10 minutes of downtime
Limit session time
------------------------
Limit session time
------------------

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

Expand All @@ -55,8 +56,8 @@ Add to `settings`:
AUTO_LOGOUT = {'SESSION_TIME': 3600}
✉️ Show messages when logging out automatically
-----------------------------------------------------
Show messages when logging out automatically
--------------------------------------------

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

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

.. note::

`messages` template variable provides by `django.contrib.messages.context_processors.messages`
context processor.

See `TEMPLATES` `OPTIONS` `context_processors` in your `settings.py` file.
See `TEMPLATES` - `OPTIONS` - `context_processors` in your `settings.py` file.

🌈 Combine configurations
----------------------------
Combine configurations
----------------------

You can combine previous configurations. For example, you may want to logout a user
in case of downtime (5 minutes or more) and not allow working within one session
Expand Down
2 changes: 1 addition & 1 deletion django_auto_logout/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.1'
__version__ = '0.3.2'

0 comments on commit ac82832

Please sign in to comment.