Skip to main content

Django app which keep track of user login history.

Project description

dj-user-login-history

A Django app which keep track of user login history.

How to install

pip install dj_user_login_history

Usage

  1. Add login_history app to INSTALLED_APPS
INSTALLED_APPS = [
    ...
    'login_history',
    ...
]
  1. Migrate database:
python manage.py migrate
  1. Now all your user's login history will be tracked to a model called LoginHistory
  2. You can check a user's active logins:
user.active_logins
  1. You can add login_history.urls to your project url to see an example page explaining the user login histores.
  2. For better understanding, read following code:
def login_histories(request):

    if not request.user.is_authenticated:
        return HttpResponse("<h1>Please login to see your login histories</h1>")\
        
    active_logins = request.user.active_logins

    active_logins_html = ""
    for login in active_logins:
        active_logins_html += f'<li>{login.ip} - {login.date_time} - {login.user_agent}</li>'

    return HttpResponse(
    f"""
        <h1>Active Logins</h1>
        <ul>
            {active_logins_html}
        </ul>
    """
    )
  1. Use the ip to grab more information directly from the Frontend instead of backend, it'll optimize performance. There're huge JS library which do the work, use any one of them.

NB: When you write your own login view, make sure you log the user in using django login

from django.contrib.auth import login as django_login

django_login(request, user)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj-user-login-history-1.0.6.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_user_login_history-1.0.6-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file dj-user-login-history-1.0.6.tar.gz.

File metadata

  • Download URL: dj-user-login-history-1.0.6.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for dj-user-login-history-1.0.6.tar.gz
Algorithm Hash digest
SHA256 7ffa4e7b07ad1438915edb25f096167882eb4fa0c60d91f1bc18995c7f68efca
MD5 b4cecac6efbe4c469325125580b014cd
BLAKE2b-256 88f9712603c73a8cfb90c7c66a157dda11d6ab90872dd7d92f5f96839eeaa3a8

See more details on using hashes here.

File details

Details for the file dj_user_login_history-1.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for dj_user_login_history-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e69798f765a75f0f01e4ba1677ead8b8abf20f7335608455c638b314fccceb5b
MD5 d6552b3431eb78f42654a830351ef51c
BLAKE2b-256 ec2c3f6f72949a45a8829afae285623e872c96b01ba35bf6c52c4766b9427773

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page