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
- Add
login_historyapp to INSTALLED_APPS
INSTALLED_APPS = [
...
'login_history',
...
]
- Migrate database:
python manage.py migrate
- Now all your user's login history will be tracked to a model called LoginHistory
- You can check a user's active logins:
user.active_logins
- You can add
login_history.urlsto your project url to see an example page explaining the user login histores. - 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>
"""
)
- Use the
ipto 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
Built Distribution
Close
Hashes for dj-user-login-history-1.0.6.tar.gz
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | 7ffa4e7b07ad1438915edb25f096167882eb4fa0c60d91f1bc18995c7f68efca |
|
| MD5 | b4cecac6efbe4c469325125580b014cd |
|
| BLAKE2b-256 | 88f9712603c73a8cfb90c7c66a157dda11d6ab90872dd7d92f5f96839eeaa3a8 |
Close
Hashes for dj_user_login_history-1.0.6-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | e69798f765a75f0f01e4ba1677ead8b8abf20f7335608455c638b314fccceb5b |
|
| MD5 | d6552b3431eb78f42654a830351ef51c |
|
| BLAKE2b-256 | ec2c3f6f72949a45a8829afae285623e872c96b01ba35bf6c52c4766b9427773 |