Skip to content

Commit 821e7e7

Browse files
authored
feat: add usersessions_list.html (#105)
Templates for seeing what sessions are active for the user /accounts/sessions/.
1 parent ab3c61c commit 821e7e7

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{% extends "usersessions/usersession_list.html" %}
2+
{% load i18n %}
3+
{% load humanize %}
4+
{% load allauth_ui %}
5+
{% block content %}
6+
{% trans "Sessions" as heading %}
7+
<div class="container mx-auto pt-1 bg-base-200">
8+
<div class="w-11/12 p-10 mx-auto mt-5 md:mt-15 lg:mt-32 rounded-lg shadow-md sm:p-5 lg:w-9/12 xl:w-8/12 md:p-10 xl:p-13 bg-base-300">
9+
<h1 class="mb-3 text-2xl">{{ heading }}</h1>
10+
{% if session_count > 1 %}
11+
{% url 'usersessions_list' as action_url %}
12+
{% translate "Sign Out Other Sessions" as button_text %}
13+
{% else %}
14+
{% url 'account_logout' as action_url %}
15+
{% translate "Sign Out" as button_text %}
16+
{% endif %}
17+
{% #form form=form url=action_url button_text=button_text %}
18+
{% csrf_token %}
19+
<div class="overflow-x-auto">
20+
<table class="table">
21+
<thead>
22+
<tr>
23+
<th>{% translate "Started At" %}</th>
24+
<th>{% translate "IP Address" %}</th>
25+
<th>{% translate "Browser" %}</th>
26+
{% if show_last_seen_at %}
27+
<th>{% translate "Last seen at" %}</th>
28+
{% endif %}
29+
</tr>
30+
</thead>
31+
<tbody>
32+
{% for session in sessions %}
33+
<tr class="hover">
34+
<td>
35+
<span title="{{ session.created_at }}">{{ session.created_at|naturaltime }}</span>
36+
</td>
37+
<td>{{ session.ip }}</td>
38+
<td>
39+
<div class="tooltip" data-tip="{{ session.user_agent }}">
40+
{{ session.user_agent | truncatechars:23 }}
41+
</div>
42+
</td>
43+
{% if show_last_seen_at %}
44+
<td>
45+
<span title="{{ session.last_seen_at }}">{{ session.last_seen_at|naturaltime }}</span>
46+
</td>
47+
{% endif %}
48+
<td>
49+
{% if session.is_current %}
50+
<div class="badge badge-md">{% translate "Current" %}</div>
51+
{% else %}
52+
{% endif %}
53+
</td>
54+
</tr>
55+
{% endfor %}
56+
</tbody>
57+
</table>
58+
</div>
59+
{% /form %}
60+
</div>
61+
</div>
62+
{% endblock content %}

tests/settings.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,22 @@
2727
]
2828

2929
THIRD_PARTY_APPS = [
30-
"rosetta",
31-
"django_extensions",
3230
"allauth_ui",
3331
"allauth",
3432
"allauth.account",
3533
"allauth.socialaccount",
36-
"allauth.socialaccount.providers.github",
37-
"allauth.socialaccount.providers.facebook",
3834
"allauth.socialaccount.providers.digitalocean",
35+
"allauth.socialaccount.providers.facebook",
36+
"allauth.socialaccount.providers.github",
3937
"allauth.socialaccount.providers.wahoo",
38+
"debug_toolbar",
39+
"django_browser_reload",
40+
"django_extensions",
41+
"rosetta",
4042
"slippers",
4143
"widget_tweaks",
42-
"django_browser_reload",
43-
"debug_toolbar",
44+
"allauth.usersessions",
45+
"django.contrib.humanize",
4446
]
4547

4648
LOCAL_APPS = ["tests"]
@@ -55,6 +57,7 @@
5557
"django.middleware.csrf.CsrfViewMiddleware",
5658
"allauth.account.middleware.AccountMiddleware",
5759
"django.contrib.auth.middleware.AuthenticationMiddleware",
60+
"allauth.usersessions.middleware.UserSessionsMiddleware",
5861
"django.contrib.messages.middleware.MessageMiddleware",
5962
"django.middleware.clickjacking.XFrameOptionsMiddleware",
6063
"django_browser_reload.middleware.BrowserReloadMiddleware",
@@ -111,3 +114,5 @@
111114
ALLAUTH_UI_THEME = "light"
112115

113116
BASE_DIR = Path(__file__).parent.parent
117+
118+
USERSESSIONS_TRACK_ACTIVITY = True

0 commit comments

Comments
 (0)