Files
django-mfa2/mfa/middleware.py
Mohamed ElKalioby 4d4d647d35 Some Fixes for pylint
2024-01-25 14:06:49 +03:00

26 lines
680 B
Python

import time
from django.http import HttpResponseRedirect
try:
from django.urls import reverse
except ImportError:
from django.core.urlresolvers import reverse # pyre-ignore[21]
from django.conf import settings
def process(request):
next_check = request.session.get("mfa", {}).get("next_check", False)
if not next_check:
return None
now = int(time.time())
if now >= next_check:
method = request.session["mfa"]["method"]
path = request.META["PATH_INFO"]
return HttpResponseRedirect(
reverse(method + "_auth")
+ "?next=%s" % (settings.BASE_URL + path).replace("//", "/")
)
return None