32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
from rest_framework.exceptions import APIException
|
|
from django.utils.timezone import now
|
|
|
|
from apps.pos_device.models import DeviceVersion, ProviderCompany, Sessions
|
|
|
|
|
|
class POSDeviceMiddleware:
|
|
REQUIRED_HEADERS = [
|
|
'device-id', 'device-mac', 'device-serial', 'device-name',
|
|
'device-sdk', 'device-provider', 'device-version',
|
|
'device-vname', 'device-lng', 'device-lot' # noqa
|
|
]
|
|
|
|
def __init__(self, get_response):
|
|
self.get_response = get_response
|
|
|
|
def __call__(self, request, *args, **kwargs):
|
|
pass
|
|
|
|
def is_post_request(self, request): # noqa
|
|
""" check if is pos request """
|
|
|
|
has_device_headers = request.headers.get('device-id') and request.headers.get('device-mac')
|
|
is_pos_api_path = request.path.startswith('/api/pos/')
|
|
return has_device_headers or is_pos_api_path
|
|
|
|
def validate_pos_request(self, request):
|
|
""" validate request headers from pos device """
|
|
|
|
data = {key: request.headers.get(key) for key in self.REQUIRED_HEADERS}
|
|
|