from django.http import HttpResponse, JsonResponse

from Platform import settings
from web.models import CustomUser


def is_staff(request):
    if request.headers.get("X-Security-Token") != settings.PLATFORM_SECURITY_TOKEN:
        return HttpResponse('', status=403)
    data = {}
    vk_id = request.GET.get('vk_id')
    if vk_id:
        data['vk_id'] = vk_id
    yandex_id = request.GET.get('yandex_id')
    if yandex_id:
        data['yandex_id'] = yandex_id
    email = request.GET.get('email')
    if email:
        data['email'] = email
    telegram_id = request.GET.get('telegram_id')
    if telegram_id:
        try:
            data['telegram_id'] = int(telegram_id)
        except:
            pass
    for key, value in data.items():
        if len(CustomUser.objects.filter(**{key: value})) != 0:
            return JsonResponse({'is_staff': True})
    return JsonResponse({'is_staff': False})
