# Path: APITaxi2/schemas.py
# TAXI_MIN_RADIUS = 150
# TAXI_MAX_RADIUS = 500
# class PageQueryStringMixin:
# class PositionMixin:
# class DepartementSchema(Schema):
# class DriverSchema(Schema):
# class RefTownSchema(Schema):
# class RefADSSchema(Schema):
# class ADSSchema(Schema):
# class RefDriverSchema(Schema):
# class VehicleSchema(Schema):
# class RefVehicleSchema(Schema):
#     class Meta:
# class TaxiPositionSchema(Schema):
# class ListTaxisQueryStringSchema(PositionMixin, Schema):
#     class Meta:
# class ZUPCSchema(Schema):
# class ZUPCGeomSchema(Schema):
# class TownSchema(Schema):
# class TaxiSchema(Schema):
# class SearchVehicleSchema(Schema):
# class SearchTaxiSchema(Schema):
# class ListTaxisAllQuerystringSchema(Schema, PageQueryStringMixin):
# class TaxiPOSTSchema(Schema):
# class TaxiPUTSchema(Schema):
# class RoleSchema(Schema):
# class ListUserQuerystringSchema(Schema, PageQueryStringMixin):
# class ManagerSchema(Schema):
# class UserSchema(Schema):
# class CustomerSchema(Schema):
# class HailTaxiRelationSchema(Schema):
# class CreateHailSchema(Schema):
# class HailVehicleSchema(Schema):
# class HailDriverSchema(Schema):
# class HailTaxiSchema(Schema):
# class HailSchema(Schema):
# class ListHailsQuerystringSchema(Schema, PageQueryStringMixin):
# class HailListSchema(Schema):
# class HailBySessionUserSchema(Schema):
# class HailBySessionTaxiSchema(Schema):
# class HailBySessionSchema(Schema):
# class HailBySessionListSchema(Schema):
# class ListHailsBySessionQuerystringSchema(Schema, PageQueryStringMixin):
# class ListZUPCQueryStringSchema(PositionMixin, Schema):
# class ListTownQueryStringSchema(Schema):
# class GeotaxiPositionSchema(PositionMixin, Schema):
# class GeotaxiSchema(Schema):
#     class Pagination(Schema):
#     class MCS(SchemaMeta):
#     class DataSchema(Schema, metaclass=MCS):
#     def check_length(self, pages):
#     def check_required(self, data, **kwargs):
#     def load(self, fields, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def check_lengths(self, data, **kwargs):
# def validate_header_name(value):
# def validate_header_value(value):
#     def check_password(self, password):
#     def check_endpoint(self, endpoint):
#     def __init__(self, current_user=None):
#     def dump(self, obj, *args, **kwargs):
#     def check_length(self, positions):
# def data_schema_wrapper(WrappedSchema, with_pagination=False):
#         def __init__(self, name, bases, attrs):
#         def validate_length(self, value):
# 
# Path: APITaxi2/validators.py
# def make_error_json_response(errors, status_code=400):
#     """Parameter errors is a dict as returned by validate_schema().
# 
#     Example of the HTTP/400 response return value:
# 
#     >>> {
#     ...  "errors": {
#     ...    "data": {
#     ...      "0": {
#     ...        "moteur_id": [
#     ...          "Not a valid integer."
#     ...        ]
#     ...      }
#     ...    }
#     ...  }
#     ... }
#     """
#     return jsonify({'errors': errors}), status_code
# 
# def validate_schema(schema, data, **kwargs):
#     try:
#         sanitized = schema.load(data, **kwargs)
#     except ValidationError as exc:
#         # Return None as sanitized data, and the error fields.
#         return (None, exc.messages)
#     return (sanitized, None)


from flask import Blueprint, request
from flask_security.utils import verify_password
from marshmallow import fields, Schema, validates_schema, ValidationError
from sqlalchemy.orm import joinedload
from APITaxi_models2 import User
from APITaxi2 import schemas
from APITaxi2.validators import (
    make_error_json_response,
    validate_schema
)


@blueprint.route('/internal/auth', methods=['POST'])
def auth():
    """Authenticate user. Request should specify either "apikey", or "email"
    and "password".
    """
    schema = DataAuthSchema()

    params, errors = validate_schema(schema, request.json)
    if errors:
        return make_error_json_response(errors)

    args = params['data'][0]

    query = User.query.options(
        joinedload(User.manager),
        joinedload(User.managed)
    ).filter_by(
        email=args['email']
    )

    if args.get('apikey'):
        query = query.filter_by(apikey=args.get('apikey'))

    user = query.one_or_none()

    if not user or (
        args.get('password') and not verify_password(args['password'], user.password)
    ):

# Path: APITaxi2/schemas.py
# TAXI_MIN_RADIUS = 150
# TAXI_MAX_RADIUS = 500
# class PageQueryStringMixin:
# class PositionMixin:
# class DepartementSchema(Schema):
# class DriverSchema(Schema):
# class RefTownSchema(Schema):
# class RefADSSchema(Schema):
# class ADSSchema(Schema):
# class RefDriverSchema(Schema):
# class VehicleSchema(Schema):
# class RefVehicleSchema(Schema):
#     class Meta:
# class TaxiPositionSchema(Schema):
# class ListTaxisQueryStringSchema(PositionMixin, Schema):
#     class Meta:
# class ZUPCSchema(Schema):
# class ZUPCGeomSchema(Schema):
# class TownSchema(Schema):
# class TaxiSchema(Schema):
# class SearchVehicleSchema(Schema):
# class SearchTaxiSchema(Schema):
# class ListTaxisAllQuerystringSchema(Schema, PageQueryStringMixin):
# class TaxiPOSTSchema(Schema):
# class TaxiPUTSchema(Schema):
# class RoleSchema(Schema):
# class ListUserQuerystringSchema(Schema, PageQueryStringMixin):
# class ManagerSchema(Schema):
# class UserSchema(Schema):
# class CustomerSchema(Schema):
# class HailTaxiRelationSchema(Schema):
# class CreateHailSchema(Schema):
# class HailVehicleSchema(Schema):
# class HailDriverSchema(Schema):
# class HailTaxiSchema(Schema):
# class HailSchema(Schema):
# class ListHailsQuerystringSchema(Schema, PageQueryStringMixin):
# class HailListSchema(Schema):
# class HailBySessionUserSchema(Schema):
# class HailBySessionTaxiSchema(Schema):
# class HailBySessionSchema(Schema):
# class HailBySessionListSchema(Schema):
# class ListHailsBySessionQuerystringSchema(Schema, PageQueryStringMixin):
# class ListZUPCQueryStringSchema(PositionMixin, Schema):
# class ListTownQueryStringSchema(Schema):
# class GeotaxiPositionSchema(PositionMixin, Schema):
# class GeotaxiSchema(Schema):
#     class Pagination(Schema):
#     class MCS(SchemaMeta):
#     class DataSchema(Schema, metaclass=MCS):
#     def check_length(self, pages):
#     def check_required(self, data, **kwargs):
#     def load(self, fields, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def dump(self, obj, *args, **kwargs):
#     def check_lengths(self, data, **kwargs):
# def validate_header_name(value):
# def validate_header_value(value):
#     def check_password(self, password):
#     def check_endpoint(self, endpoint):
#     def __init__(self, current_user=None):
#     def dump(self, obj, *args, **kwargs):
#     def check_length(self, positions):
# def data_schema_wrapper(WrappedSchema, with_pagination=False):
#         def __init__(self, name, bases, attrs):
#         def validate_length(self, value):
# 
# Path: APITaxi2/validators.py
# def make_error_json_response(errors, status_code=400):
#     """Parameter errors is a dict as returned by validate_schema().
# 
#     Example of the HTTP/400 response return value:
# 
#     >>> {
#     ...  "errors": {
#     ...    "data": {
#     ...      "0": {
#     ...        "moteur_id": [
#     ...          "Not a valid integer."
#     ...        ]
#     ...      }
#     ...    }
#     ...  }
#     ... }
#     """
#     return jsonify({'errors': errors}), status_code
# 
# def validate_schema(schema, data, **kwargs):
#     try:
#         sanitized = schema.load(data, **kwargs)
#     except ValidationError as exc:
#         # Return None as sanitized data, and the error fields.
#         return (None, exc.messages)
#     return (sanitized, None)


# Path: APITaxi2/views/internal/auth.py
from flask import Blueprint, request
from flask_security.utils import verify_password
from marshmallow import fields, Schema, validates_schema, ValidationError
from sqlalchemy.orm import joinedload
from APITaxi_models2 import User
from APITaxi2 import schemas
from APITaxi2.validators import (
    make_error_json_response,
    validate_schema
)



@blueprint.route('/internal/auth', methods=['POST'])
def auth():
    """Authenticate user. Request should specify either "apikey", or "email"
    and "password".
    """
    schema = DataAuthSchema()

    params, errors = validate_schema(schema, request.json)
    if errors:
        return make_error_json_response(errors)

    args = params['data'][0]

    query = User.query.options(
        joinedload(User.manager),
        joinedload(User.managed)
    ).filter_by(
        email=args['email']
    )

    if args.get('apikey'):
        query = query.filter_by(apikey=args.get('apikey'))

    user = query.one_or_none()

    if not user or (
        args.get('password') and not verify_password(args['password'], user.password)
    ):

        return make_error_json_response({