Added to log out the current user.
This commit is contained in:
parent
de679cf91a
commit
68be53e212
@ -65,6 +65,9 @@ def digest_login_required(function=None):
|
||||
def _wrapped_view(request, *args, **kwargs):
|
||||
if request.user.is_anonymous:
|
||||
return HttpResponse(status=401)
|
||||
if "logout" in request.session:
|
||||
del request.session["logout"]
|
||||
return HttpResponse(status=401)
|
||||
return view_func(request, *args, **kwargs)
|
||||
return _wrapped_view
|
||||
if function:
|
||||
|
@ -1,3 +1,20 @@
|
||||
from django.shortcuts import render
|
||||
from django.contrib.auth import logout
|
||||
from django.shortcuts import redirect
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@require_POST
|
||||
def logout_view(request):
|
||||
"""The view to log out a user.
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The request.
|
||||
|
||||
Returns:
|
||||
HttpRedirectResponse: The redirect response.
|
||||
"""
|
||||
logout(request)
|
||||
if "next" in request.POST:
|
||||
request.session["logout"] = True
|
||||
return redirect(request.POST["next"])
|
||||
return redirect("/")
|
||||
|
Loading…
Reference in New Issue
Block a user