Spaces:
Running
Running
File size: 749 Bytes
947c08e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import environ
from backend.module.utils import date_utils
from django.contrib.sessions.models import Session
from django.views.decorators.csrf import csrf_exempt
from django_ratelimit.decorators import ratelimit
from django.http import HttpResponse, JsonResponse, HttpResponseBadRequest
env = environ.Env()
@ratelimit(key='ip', rate='10/m')
@csrf_exempt
def delete_outdated(request):
if request.method != "POST": return HttpResponseBadRequest('Allowed POST request only!', status=400)
if request.headers.get("Worker-Token") != env("WORKER_TOKEN"): return HttpResponseBadRequest('Request Forbidden!', status=403)
Session.objects.filter(expire_date__lte=date_utils.utc_time().get()).delete()
return JsonResponse({"status":True})
|