diff --git a/setup.cfg b/setup.cfg index e9723da..6250003 100644 --- a/setup.cfg +++ b/setup.cfg @@ -36,8 +36,8 @@ classifiers = Framework :: Django :: 2.2 Framework :: Django :: 3.1 Framework :: Django :: 3.2 - Framework :: Django :: 4.0 Framework :: Django :: 4.1 + Framework :: Django :: 4.2 Programming Language :: Python Programming Language :: Python :: 3 Programming Language :: Python :: 3.6 diff --git a/src/django_forbid/__init__.py b/src/django_forbid/__init__.py index 1276d02..0a8da88 100644 --- a/src/django_forbid/__init__.py +++ b/src/django_forbid/__init__.py @@ -1 +1 @@ -__version__ = "0.1.5" +__version__ = "0.1.6" diff --git a/src/django_forbid/skills/forbid_device.py b/src/django_forbid/skills/forbid_device.py index c6fc6e7..3608aec 100644 --- a/src/django_forbid/skills/forbid_device.py +++ b/src/django_forbid/skills/forbid_device.py @@ -23,13 +23,14 @@ def __call__(self, request): devices = Settings.get("DEVICES", []) device_type = request.session.get("DEVICE") + http_ua = request.META.get("HTTP_USER_AGENT") + verified_ua = request.session.get("VERIFIED_UA", "") - # Skip if DEVICES empty. - if not devices: + # Skips if DEVICES empty or user agent is verified. + if not devices or verified_ua == http_ua: return self.get_response(request) if not device_type: - http_ua = request.META.get("HTTP_USER_AGENT") device_detector = DeviceDetector(http_ua) device_detector = device_detector.parse() device = device_detector.device_type() @@ -37,8 +38,12 @@ def __call__(self, request): request.session["DEVICE"] = device_type if Access(devices).grants(device_type): + request.session["VERIFIED_UA"] = http_ua return self.get_response(request) + # Erases the user agent from the session. + request.session["VERIFIED_UA"] = "" + # Redirects to the FORBIDDEN_DEV URL if set. if Settings.has("OPTIONS.URL.FORBIDDEN_DEV"): return redirect(Settings.get("OPTIONS.URL.FORBIDDEN_DEV")) diff --git a/src/django_forbid/skills/forbid_location.py b/src/django_forbid/skills/forbid_location.py index 4fdb413..7a5f7e5 100644 --- a/src/django_forbid/skills/forbid_location.py +++ b/src/django_forbid/skills/forbid_location.py @@ -25,7 +25,8 @@ def __call__(self, request): client_ip = address.split(",")[0].strip() verified_ip = request.session.get("VERIFIED_IP", "") - if verified_ip and verified_ip == client_ip: + # Skips if user IP is verified. + if verified_ip == client_ip: return self.get_response(request) try: