# 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',
...
]
```
2. Migrate database:
```
python manage.py migrate
```
3. Now all your user's login history will be tracked to a model called LoginHistory
4. You can check a user's active logins:
```
user.active_logins
```
5. You can add `login_history.urls` to your project url to see an example page explaining the user login histores.
6. 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>
"""
)
```
7. 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)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/farhad0085/dj-user-login-history",
"name": "dj-user-login-history",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "Farhad Hossain",
"author_email": "farhadhossain0085@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/88/f9/712603c73a8cfb90c7c66a157dda11d6ab90872dd7d92f5f96839eeaa3a8/dj-user-login-history-1.0.6.tar.gz",
"platform": null,
"description": "# dj-user-login-history\r\n\r\nA Django app which keep track of user login history.\r\n\r\n## How to install\r\n```\r\npip install dj_user_login_history\r\n```\r\n\r\n## Usage\r\n\r\n1. Add `login_history` app to INSTALLED_APPS\r\n\r\n```\r\nINSTALLED_APPS = [\r\n ...\r\n 'login_history',\r\n ...\r\n]\r\n```\r\n\r\n2. Migrate database:\r\n```\r\npython manage.py migrate\r\n```\r\n\r\n3. Now all your user's login history will be tracked to a model called LoginHistory\r\n4. You can check a user's active logins:\r\n```\r\nuser.active_logins\r\n```\r\n5. You can add `login_history.urls` to your project url to see an example page explaining the user login histores.\r\n6. For better understanding, read following code:\r\n\r\n```\r\ndef login_histories(request):\r\n\r\n if not request.user.is_authenticated:\r\n return HttpResponse(\"<h1>Please login to see your login histories</h1>\")\\\r\n \r\n active_logins = request.user.active_logins\r\n\r\n active_logins_html = \"\"\r\n for login in active_logins:\r\n active_logins_html += f'<li>{login.ip} - {login.date_time} - {login.user_agent}</li>'\r\n\r\n return HttpResponse(\r\n f\"\"\"\r\n <h1>Active Logins</h1>\r\n <ul>\r\n {active_logins_html}\r\n </ul>\r\n \"\"\"\r\n )\r\n```\r\n7. Use the `ip` to grab more information directly from the Frontend instead of backend, it'll optimize performance.\r\nThere're huge JS library which do the work, use any one of them.\r\n\r\n> NB: When you write your own login view, make sure you log the user in using django login\r\n```\r\nfrom django.contrib.auth import login as django_login\r\n\r\ndjango_login(request, user)\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Django app which keep track of user login history.",
"version": "1.0.6",
"project_urls": {
"Homepage": "https://github.com/farhad0085/dj-user-login-history"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ec2c3f6f72949a45a8829afae285623e872c96b01ba35bf6c52c4766b9427773",
"md5": "d6552b3431eb78f42654a830351ef51c",
"sha256": "e69798f765a75f0f01e4ba1677ead8b8abf20f7335608455c638b314fccceb5b"
},
"downloads": -1,
"filename": "dj_user_login_history-1.0.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d6552b3431eb78f42654a830351ef51c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8976,
"upload_time": "2024-08-09T18:02:47",
"upload_time_iso_8601": "2024-08-09T18:02:47.398828Z",
"url": "https://files.pythonhosted.org/packages/ec/2c/3f6f72949a45a8829afae285623e872c96b01ba35bf6c52c4766b9427773/dj_user_login_history-1.0.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "88f9712603c73a8cfb90c7c66a157dda11d6ab90872dd7d92f5f96839eeaa3a8",
"md5": "b4cecac6efbe4c469325125580b014cd",
"sha256": "7ffa4e7b07ad1438915edb25f096167882eb4fa0c60d91f1bc18995c7f68efca"
},
"downloads": -1,
"filename": "dj-user-login-history-1.0.6.tar.gz",
"has_sig": false,
"md5_digest": "b4cecac6efbe4c469325125580b014cd",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 5966,
"upload_time": "2024-08-09T18:02:48",
"upload_time_iso_8601": "2024-08-09T18:02:48.916817Z",
"url": "https://files.pythonhosted.org/packages/88/f9/712603c73a8cfb90c7c66a157dda11d6ab90872dd7d92f5f96839eeaa3a8/dj-user-login-history-1.0.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-09 18:02:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "farhad0085",
"github_project": "dj-user-login-history",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "dj-user-login-history"
}