Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use POST for logout requests #2502

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tabbycat/settings/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
MIDDLEWARE = [
'django.middleware.gzip.GZipMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
# User language preferences; must be after Session
Expand Down
12 changes: 7 additions & 5 deletions tabbycat/templates/nav/admin_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,13 @@
{% endfor %}

<div class="list-group-item d-inline-block">
<a href="{% url 'logout' %}" data-parent="#sidebar"
class="collapsed">
<i data-feather="log-out"></i>
<span class="d-none d-md-inline">{% trans "Log Out" %}</span>
</a>
<form id="logout-form" action="{% url 'logout' %}" data-parent="#sidebar" method="post" class="collapsed">
{% csrf_token %}
<button type="submit" class="btn btn-link">
<i data-feather="log-out"></i>
<span class="d-none d-md-inline">{% trans "Log Out" %}</span>
</button>
</form>
</div>

</div>
9 changes: 6 additions & 3 deletions tabbycat/templates/nav/top_nav_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@
<ul class="navbar-nav navbar-my-lg-0">
<li class="nav-item">
{% if user.is_authenticated %}
<a class="nav-link" href="{% url 'logout' %}">
{% trans "Log Out" %} ({{ user }})
</a>
<form id="logout-form" action="{% url 'logout' %}" method="post">
{% csrf_token %}
<button type="submit" class="btn btn-link nav-link">
{% trans "Log Out" %} ({{ user }})
</button>
</form>
{% else %}
<a class="nav-link" href="{% url 'login' %}">
{% trans "Login" %}
Expand Down
2 changes: 1 addition & 1 deletion tabbycat/templates/scss/modules/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}

// Fix bad inheritance
.list-group-item .btn .feather {
.list-group-item .btn:not(.btn-link) .feather {
margin-right: 0;
}

Expand Down
55 changes: 32 additions & 23 deletions tabbycat/templates/scss/modules/nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
border-right: 0;
padding: 0;

a {
a,
form > button {
color: $sidebar-muted-text;
display: block;

Expand Down Expand Up @@ -223,16 +224,20 @@
// Applies just to tablets
@include media-breakpoint-up(md) {

.admin-sidebar .list-group-item a {
font-size: 12px;
padding: 0.5rem 0.5rem;
.admin-sidebar .list-group-item {

.feather {
width: 12px;
height: 12px;
padding-right: 2px;
margin-right: 0;
padding-bottom: 2px;
a,
form > button {
font-size: 12px;
padding: 0.5rem 0.5rem;

.feather {
width: 12px;
height: 12px;
padding-right: 2px;
margin-right: 0;
padding-bottom: 2px;
}
}
}

Expand All @@ -258,20 +263,24 @@
// Applies just to screens
@include media-breakpoint-up(lg) {

.admin-sidebar .list-group-item a {
font-size: $font-size-base;
padding: 0.5rem 1rem;

.feather {
width: 20px;
height: 16px;
padding-right: 4px;
}
.admin-sidebar .list-group-item {

.feather-chevron-down,
.feather-chevron-up {
margin-top: 2px;
margin-right: 0;
a,
form > button {
font-size: $font-size-base;
padding: 0.5rem 1rem;

.feather {
width: 20px;
height: 16px;
padding-right: 4px;
}

.feather-chevron-down,
.feather-chevron-up {
margin-top: 2px;
margin-right: 0;
}
}
}

Expand Down
21 changes: 18 additions & 3 deletions tabbycat/tournaments/templates/site_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,24 @@
{% url 'password_change' as url %}
{% include "components/item-action.html" with icon="rotate-cw" %}

{% blocktrans asvar text %}Log Out ({{ user }}){% endblocktrans %}
{% url 'logout' as url %}
{% include "components/item-action.html" with icon="log-out" %}
<form id="logout-link-form" method="post" action="{% url 'logout' %}" class="list-group-item list-group-item-action text-primary">
{% csrf_token %}
<button type="submit" class="btn btn-link p-0 list-group-item-action text-primary">
<div class="row align-items-center">
<div class="col-auto pr-1">
<i data-feather="log-out"></i>
</div>

<div class="col pl-0 pr-0">
{% blocktrans %}Log Out ({{ user }}){% endblocktrans %}
</div>

<div class="col-auto pr-1">
<i data-feather="chevron-right"></i>
</div>
</div>
</button>
</form>

{% else %}

Expand Down
Loading