# Path: app/api/auth.py
# def authorization_required(func=None):
#     def decorator(view_func):
#         def wrapper(request, *args, **kwargs):
#             api_key = 'HTTP_X_TAVERNATOKEN'
#             if api_key not in request.META:
#                 data = {'message': 'Set your api_key in X-TavernaToken header.'}
#                 return JsonResponse(data, status=401)
# 
#             try:
#                 ApiKey.objects.get(token=request.META[api_key], revoked=False)
#             except (ApiKey.DoesNotExist, TypeError):
#                 data = {'message': 'Invalid Token.'}
#                 return JsonResponse(data, status=401)
# 
#             return view_func(request, *args, **kwargs)
# 
#         return wrapper
# 
#     if func:
#         return decorator(func)
# 
#     return decorator


from django.conf.urls import url, include
from django.contrib import admin
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
from app.api.auth import authorization_required



urlpatterns = [
    url(r'^api/', include('app.api.urls')),
    url(r'^', admin.site.urls),

# Path: app/api/auth.py
# def authorization_required(func=None):
#     def decorator(view_func):
#         def wrapper(request, *args, **kwargs):
#             api_key = 'HTTP_X_TAVERNATOKEN'
#             if api_key not in request.META:
#                 data = {'message': 'Set your api_key in X-TavernaToken header.'}
#                 return JsonResponse(data, status=401)
# 
#             try:
#                 ApiKey.objects.get(token=request.META[api_key], revoked=False)
#             except (ApiKey.DoesNotExist, TypeError):
#                 data = {'message': 'Invalid Token.'}
#                 return JsonResponse(data, status=401)
# 
#             return view_func(request, *args, **kwargs)
# 
#         return wrapper
# 
#     if func:
#         return decorator(func)
# 
#     return decorator


# Path: core/urls.py
from django.conf.urls import url, include
from django.contrib import admin
from django.views.decorators.csrf import csrf_exempt
from graphene_django.views import GraphQLView
from app.api.auth import authorization_required




urlpatterns = [
    url(r'^api/', include('app.api.urls')),
    url(r'^', admin.site.urls),

    url(r'^api$', csrf_exempt(authorization_required(GraphQLView.as_view()))),