Skip to content

Commit

Permalink
Remplace la vue de logout par la LogoutView de Django (#6272)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arnaud-D authored Mar 28, 2022
1 parent 59e6187 commit 2d0324a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
5 changes: 3 additions & 2 deletions zds/member/urls.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib.auth.views import LogoutView
from django.urls import re_path, path

from zds.member.views import MemberList
Expand All @@ -16,7 +17,7 @@
member_from_ip,
modify_profile,
)
from zds.member.views.login import login_view, logout_view
from zds.member.views.login import login_view
from zds.member.views.hats import (
HatsSettings,
RequestedHatsList,
Expand Down Expand Up @@ -103,7 +104,7 @@
re_path(r"^casquettes/retirer/(?P<user_pk>\d+)/(?P<hat_pk>\d+)/$", remove_hat, name="remove-hat"),
# membership
re_path(r"^connexion/$", login_view, name="member-login"),
re_path(r"^deconnexion/$", logout_view, name="member-logout"),
re_path(r"^deconnexion/$", LogoutView.as_view(), name="member-logout"),
re_path(r"^inscription/$", RegisterView.as_view(), name="register-member"),
re_path(r"^reinitialisation/$", forgot_password, name="member-forgot-password"),
re_path(r"^validation/$", SendValidationEmailView.as_view(), name="send-validation-email"),
Expand Down
15 changes: 1 addition & 14 deletions zds/member/views/login.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from django.contrib import messages
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login
from django.contrib.auth.models import User
from django.template.context_processors import csrf
from django.urls import reverse, resolve, Resolver404, NoReverseMatch
from django.shortcuts import redirect, render, get_object_or_404
from django.utils.translation import gettext_lazy as _
from django.views.decorators.http import require_POST

from zds.member.forms import LoginForm
from zds.member.models import Profile
Expand Down Expand Up @@ -101,14 +99,3 @@ def login_view(request):
csrf_tk["error"] = error
csrf_tk["form"] = form
return render(request, "member/login.html", {"form": form, "csrf_tk": csrf_tk})


@login_required
@require_POST
def logout_view(request):
"""Log user out."""

logout(request)
request.session.clear()
response = redirect(reverse("homepage"))
return response
2 changes: 2 additions & 0 deletions zds/settings/abstract_base/zds.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

zds_config = config.get("zds", {})

LOGOUT_REDIRECT_URL = "homepage"

GEOIP_PATH = str(BASE_DIR / "geodata")
GEOIP_CITY = "GeoLite2-City.mmdb"

Expand Down

0 comments on commit 2d0324a

Please sign in to comment.