# 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 pwd_clear2 != pwd_clear:
            content['password2'] = "Les deux mots de passe doivent être identiques !"
        # hash password
        pwd_hash = _hash_pwd(pwd_clear)
        # realisation si pas d'erreur
        if len(content.keys()) == 0:
            content = "Cette adresse email est déjà attribuée à un utilisateur."
            # verification de l'existence de l'utilisateur
            if not db.user_exists(email):
                # creation de l'utilisateur
                db.create_user(firstname, lastname, email, pwd_hash, promo)
                # chargement de l'utilisateur créé dans la session (connexion automatique après inscription)
                _load_user(session, email, pwd_hash)
                # mise à jour des variables de réponse 
                err = False
                content = 'ok'
                msg = """A new user joined MapIF! 
*{0} {1}* 
promo *{2}* 
*{3}*
:D
""".format(firstname, lastname, promo, email)
                modlgr.info(msg)
    return json_response(Response(err, content).json(), status_code=200)
#-------------------------------------------------------------------------------
# account_update_names
#   This route can be used to update user profile firstname and lastname
#-------------------------------------------------------------------------------
@app.route('/account/update/names', methods=['PATCH'])
@internal_error_handler('4CC0U7UPD4T3NAM35K0')

# 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 pwd_clear2 != pwd_clear:
            content['password2'] = "Les deux mots de passe doivent être identiques !"
        # hash password
        pwd_hash = _hash_pwd(pwd_clear)
        # realisation si pas d'erreur
        if len(content.keys()) == 0:
            content = "Cette adresse email est déjà attribuée à un utilisateur."
            # verification de l'existence de l'utilisateur
            if not db.user_exists(email):
                # creation de l'utilisateur
                db.create_user(firstname, lastname, email, pwd_hash, promo)
                # chargement de l'utilisateur créé dans la session (connexion automatique après inscription)
                _load_user(session, email, pwd_hash)
                # mise à jour des variables de réponse 
                err = False
                content = 'ok'
                msg = """A new user joined MapIF! 
*{0} {1}* 
promo *{2}* 
*{3}*
:D
""".format(firstname, lastname, promo, email)
                modlgr.info(msg)
    return json_response(Response(err, content).json(), status_code=200)
#-------------------------------------------------------------------------------
# account_update_names
#   This route can be used to update user profile firstname and lastname
#-------------------------------------------------------------------------------
@app.route('/account/update/names', methods=['PATCH'])
@internal_error_handler('4CC0U7UPD4T3NAM35K0')

@require_connected()