# Path: runner/forms.py
# class LoginForm(forms.Form):
# class Password(forms.Form):
# class RouteAddForm(forms.Form):
# class StopsForm(forms.Form):
# class RouteForm(forms.Form):
# class BusBookForm(forms.Form):
# class UserSignupForm(ModelForm):
#     class Meta:
# class AuthForm(forms.Form):
# class TokenForm(forms.Form):
# class PassForm(forms.Form):
# class BookingForm(ModelForm):
#     class Meta:
# 
# Path: e_auth/middleware.py
# def protector(func):
#     def decorator(request, *args, **kwargs):
#         app_name = request.resolver_match.app_name
#         from django.conf import settings
#         allowed_apps = settings.EAUTH_ALLOWEDAPPS
#         if app_name in allowed_apps:
#             return func(request, *args, **kwargs)
# 
#         token = request.GET.get('token') or request.POST.get('token')
#         response = HttpResponse()
#         if token:
#             try:
#                 auth = Authorize.objects.get(auth_token=token)
#             
#                 if(timezone.now() < auth.expire_time):
#                     return func(request, *args, **kwargs)
#                 else:
#                     retdict = {}
#                     retdict['status'] = 400
#                     retdict['data'] = "Token Has Expired"
#                     retdict['detail'] = "Invalid Token"
#                     response.status_code = 400
#                     serialdata = json.dumps(retdict)
#                     response.content = serialdata
#                     return response
#             except:
#                     retdict = {}
#                     retdict['status'] = 400
#                     retdict['data'] = "User Not Authorized"
#                     retdict['detail'] = "Invalid Token"
#                     response.status_code = 400
#                     serialdata = json.dumps(retdict)
#                     response.content = serialdata
#                     return response
# 
#         else:
#             retdict = {}
#             retdict['status'] = 404
#             retdict['data'] = "Access Token Is Required"
#             retdict['detail'] = "Unverified Request to restricted url"
#             response.status_code = 404
#             serialdata = json.dumps(retdict)
#             response.content = serialdata
#             return response
# 
#     return decorator


from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.db import connection
from runner.queries import *
from runner.serializers import *
from rest_framework.decorators import api_view
from rest_framework.response import Response
from runner import forms
from rest_framework import viewsets
from MySQLdb.cursors import SSDictCursor
from django.core.mail import send_mail
from runner.models import *
from e_auth.middleware import protector
import MySQLdb as mysql
import json
#from runner.serializers import StopSerializer, RouteSerializer, RouteDetailSerializer

#from django.core.mail import send_mail


def dictfetchall(cursor):
    "Return all rows from a cursor as a dict"
    columns = [col[0] for col in cursor.description]
    return [
        dict(zip(columns, row))
        for row in cursor.fetchall()
    ]


def index(request):
    return HttpResponse("Hello kapil")



@api_view(['GET'])

# Path: runner/forms.py
# class LoginForm(forms.Form):
# class Password(forms.Form):
# class RouteAddForm(forms.Form):
# class StopsForm(forms.Form):
# class RouteForm(forms.Form):
# class BusBookForm(forms.Form):
# class UserSignupForm(ModelForm):
#     class Meta:
# class AuthForm(forms.Form):
# class TokenForm(forms.Form):
# class PassForm(forms.Form):
# class BookingForm(ModelForm):
#     class Meta:
# 
# Path: e_auth/middleware.py
# def protector(func):
#     def decorator(request, *args, **kwargs):
#         app_name = request.resolver_match.app_name
#         from django.conf import settings
#         allowed_apps = settings.EAUTH_ALLOWEDAPPS
#         if app_name in allowed_apps:
#             return func(request, *args, **kwargs)
# 
#         token = request.GET.get('token') or request.POST.get('token')
#         response = HttpResponse()
#         if token:
#             try:
#                 auth = Authorize.objects.get(auth_token=token)
#             
#                 if(timezone.now() < auth.expire_time):
#                     return func(request, *args, **kwargs)
#                 else:
#                     retdict = {}
#                     retdict['status'] = 400
#                     retdict['data'] = "Token Has Expired"
#                     retdict['detail'] = "Invalid Token"
#                     response.status_code = 400
#                     serialdata = json.dumps(retdict)
#                     response.content = serialdata
#                     return response
#             except:
#                     retdict = {}
#                     retdict['status'] = 400
#                     retdict['data'] = "User Not Authorized"
#                     retdict['detail'] = "Invalid Token"
#                     response.status_code = 400
#                     serialdata = json.dumps(retdict)
#                     response.content = serialdata
#                     return response
# 
#         else:
#             retdict = {}
#             retdict['status'] = 404
#             retdict['data'] = "Access Token Is Required"
#             retdict['detail'] = "Unverified Request to restricted url"
#             response.status_code = 404
#             serialdata = json.dumps(retdict)
#             response.content = serialdata
#             return response
# 
#     return decorator


# Path: runner/views.py
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.db import connection
from runner.queries import *
from runner.serializers import *
from rest_framework.decorators import api_view
from rest_framework.response import Response
from runner import forms
from rest_framework import viewsets
from MySQLdb.cursors import SSDictCursor
from django.core.mail import send_mail
from runner.models import *
from e_auth.middleware import protector
import MySQLdb as mysql
import json

#from runner.serializers import StopSerializer, RouteSerializer, RouteDetailSerializer

#from django.core.mail import send_mail


def dictfetchall(cursor):
    "Return all rows from a cursor as a dict"
    columns = [col[0] for col in cursor.description]
    return [
        dict(zip(columns, row))
        for row in cursor.fetchall()
    ]


def index(request):
    return HttpResponse("Hello kapil")



@api_view(['GET'])

@protector