Metadata-Version: 2.1
Name: django-auto-logout
Version: 0.4.0
Summary: Auto logout a user after specific time in Django
Home-page: https://github.com/bugov/django-auto-logout
Author: Georgy Bazhukov
Author-email: georgy.bazhukov@gmail.com
License: BSD
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Framework :: Django :: 3.0
Classifier: Framework :: Django :: 3.1
Classifier: Framework :: Django :: 3.2
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Requires: django
Requires: setuptools
Requires: wheel
Description-Content-Type: text/x-rst
License-File: LICENSE

django-auto-logout
==================

.. image:: https://app.travis-ci.com/bugov/django-auto-logout.svg?branch=master
    :target: 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
------------

.. code:: bash

    pip install django-auto-logout


Append to `settings` middlewares:

.. code:: python

    MIDDLEWARE = [
    ...
        '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`:

.. code:: python

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

or the same, but with `datetime.timedelta` (more semantically):

.. code:: python

    AUTO_LOGOUT = {'IDLE_TIME': timedelta(minutes=10)}

Limit session time
------------------

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

Add to `settings`:

.. code:: python

    AUTO_LOGOUT = {'SESSION_TIME': 3600}

or the same, but with `datetime.timedelta` (more semantically):

.. code:: python

    AUTO_LOGOUT = {'SESSION_TIME': timedelta(hours=1)}

Show messages when logging out automatically
--------------------------------------------

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

.. code:: 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:

.. code:: 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:


.. code:: python

    from datetime import timedelta

    AUTO_LOGOUT = {
        'IDLE_TIME': timedelta(minutes=5),
        'SESSION_TIME': timedelta(minutes=30),
        'MESSAGE': 'The session has expired. Please login again to continue.',
    }


