1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2025-07-31 12:41:08 +00:00
webvirtcloud/webvirtcloud/middleware.py
lando814 2997e130ff
Update middleware.py
created new DisableCSRFMiddleware to mitigate CSRF cookie error after login
2025-05-19 17:24:20 +02:00

31 lines
986 B
Python

from django.contrib import messages
from django.shortcuts import render
from django.utils.translation import gettext_lazy as _
from libvirt import libvirtError
class ExceptionMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
return self.get_response(request)
def process_exception(self, request, exception):
if isinstance(exception, libvirtError):
messages.error(
request,
_("libvirt Error - %(exception)s") % {"exception": exception},
)
return render(request, "500.html", status=500)
# TODO: check connecting to host via VPN
class DisableCSRFMiddleware(object):
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
setattr(request, '_dont_enforce_csrf_checks', True)
response = self.get_response(request)
return response