Skip to content

Commit

Permalink
add logout view, redirection depending if user logged with magic link…
Browse files Browse the repository at this point in the history
… or ProConnect (WIP, tests missing)
  • Loading branch information
vincentporte committed Nov 7, 2024
1 parent 7412416 commit 33dc422
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions lacommunaute/forum_member/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from urllib.parse import urlencode

from django.conf import settings
from django.contrib.auth import login
from django.contrib.auth import login, logout
from django.contrib.auth.tokens import default_token_generator
from django.core.mail import send_mail
from django.http import HttpResponseRedirect
from django.shortcuts import redirect, render
from django.shortcuts import render
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import force_bytes, force_str
Expand Down Expand Up @@ -143,3 +143,7 @@ def login_with_link(request, uidb64, token):

return HttpResponseRedirect(reverse("members:login"))


def logout_view(request):
logout(request)
return HttpResponseRedirect(reverse("pages:home"))
8 changes: 2 additions & 6 deletions lacommunaute/templates/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@
<li>
<div class="dropdown-divider"></div>
</li>
<li>
<a class="dropdown-item text-danger" id="js-logout" href="{% url 'openid_connect:logout' %}">Déconnexion</a>
</li>
<li>{% include "registration/includes/logout_link.html" %}</li>
</ul>
</div>
</li>
Expand Down Expand Up @@ -275,9 +273,7 @@ <h4 class="h5 mb-0 btn-ico align-items-center" id="offcanvasApplyFiltersLabel">
<li>
<div class="dropdown-divider"></div>
</li>
<li>
<a class="dropdown-item text-danger" id="js-logout" href="{% url 'openid_connect:logout' %}">Déconnexion</a>
</li>
<li>{% include "registration/includes/logout_link.html" %}</li>
</ul>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions lacommunaute/templates/registration/includes/logout_link.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% if request.session.MAGIC_LINK %}
{% url 'members:logout' as logout_url %}
{% else %}
{% url 'openid_connect:logout' as logout_url %}
{% endif %}
<a class="dropdown-item text-danger" id="js-logout" href="{{ logout_url }}"">Déconnexion</a>

0 comments on commit 33dc422

Please sign in to comment.