# Path: runner/models.py
# class User(UserAbstract):
#     def __str__(self):
#         return self.name ;
#     class Meta:
#         managed = True
#         db_table = 'User'
# 
# 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.models import Q
from taxi.serializers import *
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.core.mail import send_mail
from taxi.models import *
from runner.models import User
from datetime import timedelta, datetime
from django.utils import timezone
from e_auth.middleware import protector
import urllib, urllib2
import json
            response.data = serial_taxi.data
            return response
        except:
            response.data = "TAXI NOT FOUND"
            return response
    else:
        response.data = "Corrupted URL"
        return response


@api_view(['GET'])
@protector
def taxi_choice(request):
    choicedict = {}
    for key in request.GET.keys():
        choicedict[key] = request.GET[key]
    taxis = Taxi.objects.filter(**choicedict)
    serial_taxi = TaxiSerializer(taxis, many=True)
    return Response(serial_taxi.data)

@api_view(['POST'])
@protector
def book_taxi(request):
    #try:
        uid = request.POST['user']
        tid = request.POST['taxi']
        j_time = request.POST['journey_time']
        src = request.POST['source']
        dst = request.POST['dest']
        payment = request.POST['payment_status']

# Path: runner/models.py
# class User(UserAbstract):
#     def __str__(self):
#         return self.name ;
#     class Meta:
#         managed = True
#         db_table = 'User'
# 
# 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: taxi/views.py
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.db.models import Q
from taxi.serializers import *
from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.core.mail import send_mail
from taxi.models import *
from runner.models import User
from datetime import timedelta, datetime
from django.utils import timezone
from e_auth.middleware import protector
import urllib, urllib2
import json

            response.data = serial_taxi.data
            return response
        except:
            response.data = "TAXI NOT FOUND"
            return response
    else:
        response.data = "Corrupted URL"
        return response


@api_view(['GET'])
@protector
def taxi_choice(request):
    choicedict = {}
    for key in request.GET.keys():
        choicedict[key] = request.GET[key]
    taxis = Taxi.objects.filter(**choicedict)
    serial_taxi = TaxiSerializer(taxis, many=True)
    return Response(serial_taxi.data)

@api_view(['POST'])
@protector
def book_taxi(request):
    #try:
        uid = request.POST['user']
        tid = request.POST['taxi']
        j_time = request.POST['journey_time']
        src = request.POST['source']
        dst = request.POST['dest']
        payment = request.POST['payment_status']

        user = User.objects.get(id=uid)