# Path: core/modules/validator.py
# _VALIDATORS_ = {
#     'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
#     'alphanum': re.compile('^\w+$'),
#     'int': re.compile('^\d+$'),
#     'double': re.compile('^\d+(\.\d+)?$'),
#     'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
#     'year': re.compile('^\d{4}$'),
#     'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
# }
# def validate(field, vtype=None):
# def is_empty(field):
# def check_captcha(request):
# def normalize_filter(search_filter):
# def test():
# 
# Path: core/modules/ini.py
# _CONFIG_ = None
#         _CONFIG_ = configparser.ConfigParser()
# def init(filename):
# def getenv(env_var, default=None):
# def config(section, option, env_var=None, default=None, boolean=False):
# def test():
# 
# Path: core/modules/wrappers.py
# def internal_error_handler(err_code):
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             try:
#                 return f(*args, **kwargs)
#             except Exception as e:
#                 timestamp = time.strftime('%d%m%H%M%S')
#                 desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
#                     f.__name__, timestamp
#                 )
#                 modlgr.exception(desc)
#                 code = '{0}.{1}'.format(err_code, timestamp)
#                 resp = Response(has_error=True, code=code, content='')
#                 return json_response(resp.json(), status_code=500)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_connected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if not session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas connecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_disconnected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas déconnecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


import os
import uuid
import locale
import hashlib
import binascii
import datetime
from flask                          import Flask
from flask                          import request
from flask                          import session
from flask                          import redirect
from flask                          import abort
from flask                          import render_template
from flask                          import flash
from flask                          import escape
from flask_responses                import json_response
from flask_responses                import xml_response
from flask_responses                import auto_response
from flask_cors                     import CORS
from core.modules                   import db
from core.modules                   import validator
from core.modules                   import ini
from core.modules                   import logger
from core.modules                   import emails
from core.modules.wrappers          import internal_error_handler
from core.modules.wrappers          import require_connected
from core.modules.wrappers          import require_disconnected
from core.classes.response          import Response
from core.classes.slack_log_handler import SlackLogHandler
    if metadata['reason'] not in db.META_REASON_ENUM:
        content['meta']['reason'] = "La valeur de la métadonnée raison est invalide."
    if len(content.keys()) == 0:
        # update timestamp
        content = "La mise à jour de la localisation est un échec. Une erreur de persistence s'est produite."
        if db.update_user_location(uid, ulid, timestamp, metadata):
            err = False
            content = "La localisation a été mise à jour."
    return json_response(Response(err, content).json(), status_code=200)
#-------------------------------------------------------------------------------
# location_delete
#   This route can be used to delete a user location
#-------------------------------------------------------------------------------
@app.route('/user/location/delete', methods=['DELETE'])
@internal_error_handler('L0C4T10ND3L3T3K0')
def location_delete():
    # recupération des données du post
    uid = session['user']['id']
    ulid = escape(request.form['ulid'].strip())
    # vérification des champs
    content = {}
    err = True
    if not validator.validate(ulid, 'int'):
        content['ulid'] = "L'ulid transmis ne respecte pas le format attendu: nombre entier."
    if len(content.keys()) == 0:
        # delete location 
        content = "La suppression de la localisation n'a pas aboutie !"
        if db.delete_user_location(uid, ulid):
            err = False
            content = "La localisation a été supprimée de votre historique."

# Path: core/modules/validator.py
# _VALIDATORS_ = {
#     'email': re.compile('^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$'),
#     'alphanum': re.compile('^\w+$'),
#     'int': re.compile('^\d+$'),
#     'double': re.compile('^\d+(\.\d+)?$'),
#     'phone': re.compile('^(\+\d{2}(\s)?\d|\d{2})(\s)?(\d{2}(\s)?){4}$'),
#     'year': re.compile('^\d{4}$'),
#     'timestamp': re.compile('^\d{4}(-\d{2}){2}$')
# }
# def validate(field, vtype=None):
# def is_empty(field):
# def check_captcha(request):
# def normalize_filter(search_filter):
# def test():
# 
# Path: core/modules/ini.py
# _CONFIG_ = None
#         _CONFIG_ = configparser.ConfigParser()
# def init(filename):
# def getenv(env_var, default=None):
# def config(section, option, env_var=None, default=None, boolean=False):
# def test():
# 
# Path: core/modules/wrappers.py
# def internal_error_handler(err_code):
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             try:
#                 return f(*args, **kwargs)
#             except Exception as e:
#                 timestamp = time.strftime('%d%m%H%M%S')
#                 desc = '`mapif.{0}()` at `{1}` error: details below.'.format(
#                     f.__name__, timestamp
#                 )
#                 modlgr.exception(desc)
#                 code = '{0}.{1}'.format(err_code, timestamp)
#                 resp = Response(has_error=True, code=code, content='')
#                 return json_response(resp.json(), status_code=500)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_connected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if not session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas connecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/modules/wrappers.py
# def require_disconnected():
#     def wrapper(f):
#         @wraps(f)
#         def wrapped_f(*args, **kwargs):
#             if session.get('user', None):
#                 resp = Response(True, "Opération interdite vous n'êtes pas déconnecté !")
#                 return json_response(resp.json(), status_code=403)
#             else:
#                 return f(*args, **kwargs)
#         return wrapped_f
#     return wrapper
# 
# Path: core/classes/response.py
# class Response(object):
#     def __init__(self, has_error = True, content = {}, code=None):
#         super(Response, self).__init__()
#         self.has_error = has_error
#         self.content = content
#         self.code = code
#     #---------------------------------------------------------------------------
#     # json
#     #---------------------------------------------------------------------------
#     def json(self):
#         return {
#             'has_error': self.has_error, 
#             'content': self.content, 
#             'code': self.code
#         }
#     #---------------------------------------------------------------------------
#     # dumps
#     #---------------------------------------------------------------------------
#     def dumps(self, indent=None):
#         return json.dumps(self.json(), indent=indent)


# Path: core/mapif.py
import os
import uuid
import locale
import hashlib
import binascii
import datetime
from flask                          import Flask
from flask                          import request
from flask                          import session
from flask                          import redirect
from flask                          import abort
from flask                          import render_template
from flask                          import flash
from flask                          import escape
from flask_responses                import json_response
from flask_responses                import xml_response
from flask_responses                import auto_response
from flask_cors                     import CORS
from core.modules                   import db
from core.modules                   import validator
from core.modules                   import ini
from core.modules                   import logger
from core.modules                   import emails
from core.modules.wrappers          import internal_error_handler
from core.modules.wrappers          import require_connected
from core.modules.wrappers          import require_disconnected
from core.classes.response          import Response
from core.classes.slack_log_handler import SlackLogHandler

    if metadata['reason'] not in db.META_REASON_ENUM:
        content['meta']['reason'] = "La valeur de la métadonnée raison est invalide."
    if len(content.keys()) == 0:
        # update timestamp
        content = "La mise à jour de la localisation est un échec. Une erreur de persistence s'est produite."
        if db.update_user_location(uid, ulid, timestamp, metadata):
            err = False
            content = "La localisation a été mise à jour."
    return json_response(Response(err, content).json(), status_code=200)
#-------------------------------------------------------------------------------
# location_delete
#   This route can be used to delete a user location
#-------------------------------------------------------------------------------
@app.route('/user/location/delete', methods=['DELETE'])
@internal_error_handler('L0C4T10ND3L3T3K0')
def location_delete():
    # recupération des données du post
    uid = session['user']['id']
    ulid = escape(request.form['ulid'].strip())
    # vérification des champs
    content = {}
    err = True
    if not validator.validate(ulid, 'int'):
        content['ulid'] = "L'ulid transmis ne respecte pas le format attendu: nombre entier."
    if len(content.keys()) == 0:
        # delete location 
        content = "La suppression de la localisation n'a pas aboutie !"
        if db.delete_user_location(uid, ulid):
            err = False
            content = "La localisation a été supprimée de votre historique."

    return json_response(Response(err, content).json(), status_code=200)