from flask import make_response, request, current_app, Flask, jsonify
from functools import update_wrapper
import json
import wrapper as wp
import ela_user_account as eua
import prj_common as pc
from six import string_types
from datetime import timedelta
import Ela_Spacy as ls
import user_message_mgt as um
import user_session as us

import partners as pa
import prj_common as mycommon
import ela_index_bdd_classes as ela_index_class
import class_mgt as cm
import Dev_api_functions as dev_function
from flask_cors import CORS, cross_origin
import time
from OpenSSL import SSL
from flask import redirect
from flask import Flask, render_template, request, redirect, url_for
import articles_avis as aa
import GlobalVariable as MYSY_GV
import youtubes_analyse as YTA
import test_perso as TP
import ela_factures_mgt as invoice
import product_service as PS
import ela_factures_mgt as factures
import statistics as Stat
import strype_payement as Stripe
import Inscription_mgt as inscription
import emargement as emargement
import Session_Formation as SF
import email_mgt as emails
import email_inscription_mgt as emails_support
import opco as opco
import Attestation_Certificat as Att_Cert

app = Flask(__name__)
cors = CORS(app, resources={r"/foo": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['UPLOAD_FOLDER'] = MYSY_GV.upload_folder
app.env = "Production"
app.debug = "Production"

@app.before_request
def before_request():
    if mycommon.check_source_ipv4(str(request.remote_addr)) is False:
        return "Security check : '" + request.remote_addr + "' is not autorized", 404


def crossdomain(origin=None, methods=None, headers=None, max_age=21600,
                attach_to_all=True, automatic_options=True):
    """Decorator function that allows crossdomain requests.
      Courtesy of
      https://blog.skyred.fi/articles/better-crossdomain-snippet-for-flask.html
    """
    if methods is not None:
        methods = ', '.join(sorted(x.upper() for x in methods))
    # use str instead of basestring if using Python 3.x
    if headers is not None and not isinstance(headers, str):
        headers = ', '.join(x.upper() for x in headers)
    # use str instead of basestring if using Python 3.x
    if not isinstance(origin, str):
        origin = ', '.join(origin)
    if isinstance(max_age, timedelta):
        max_age = max_age.total_seconds()

    def get_methods():
        """ Determines which methods are allowed
        """
        if methods is not None:
            return methods

        options_resp = current_app.make_default_options_response()
        return options_resp.headers['allow']

    def decorator(f):
        """The decorator function
        """
        def wrapped_function(*args, **kwargs):
            """Caries out the actual cross domain code
            """
            if automatic_options and request.method == 'OPTIONS':
                resp = current_app.make_default_options_response()
            else:
                resp = make_response(f(*args, **kwargs))
            if not attach_to_all and request.method != 'OPTIONS':
                return resp

            h = resp.headers
            h['Access-Control-Allow-Origin'] = origin
            h['Access-Control-Allow-Methods'] = get_methods()
            h['Access-Control-Max-Age'] = str(max_age)
            h['Access-Control-Allow-Credentials'] = 'true'
            h['Access-Control-Allow-Headers'] = \
                "Origin, X-Requested-With, Content-Type, Accept, Authorization"
            if headers is not None:
                h['Access-Control-Allow-Headers'] = headers
            return resp

        f.provide_automatic_options = False
        return update_wrapper(wrapped_function, f)
    return decorator

@app.after_request
def after_request(response):
  response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
  response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')

  return response



'''
cette API gere le login et la creation du token
'''
@app.route('/myclass/api/login/', methods=['POST','GET'])
@crossdomain(origin='*')
def login():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = us.login(payload)
    return jsonify(status=status, message=retval)



'''
cette API recupere les objectifs d'un utilisateur

La clé est l'adresse email.
si le nom de la formation est fourni, alors l'api va retourner la formation donnée
'''
@app.route('/myclass/api/get_user_objectif/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_user_objectif():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_user_objectif  : payload = ",payload)
    status, retval = eua.get_user_objectif(payload)
    return jsonify(status=status, message=retval)


'''
Cette API desactive un objectif.
les clés sont : 
- adresse email
- nom de l'objectif

'''
@app.route('/myclass/api/desable_user_objectif/', methods=['POST'])
@crossdomain(origin='*')
def desable_user_objectif():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.desable_user_objectif(payload)
    return jsonify(status=status, message=retval)



'''
Cette API recupere l'historique de recherche
d'un utilisateur
'''
@app.route('/myclass/api/get_user_recherche_history/', methods=['POST','POST'])
@crossdomain(origin='*')
def get_user_recherche_history():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.get_user_recherche_history(payload)
    return jsonify(status=status, message=retval)


'''
Cette API ajoute un objectif à un utilisateur
la clé est l'adresse email
'''
@app.route('/myclass/api/add_update_user_objectif/', methods=['POST'])
@crossdomain(origin='*')
def add_update_user_objectif():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### add_update_user_objectif payload = ",payload)
    status, retval = eua.add_update_user_objectif(payload)  
    return jsonify(status=status, message=retval)


"""
Cette API met à jour le profile d'un utilisateur
"""
@app.route('/myclass/api/add_update_user_profile/', methods=['POST'])
@crossdomain(origin='*')
def add_update_user_profile():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### add_update_user_profile : payload = ",payload)
    status, retval = eua.add_update_user_profile(payload)
    return jsonify(status=status, message=retval)

"""
API de recuperation du profils d'un utilisateur
"""
@app.route('/myclass/api/Get_user_profile/', methods=['POST','GET'])
@crossdomain(origin='*')
def Get_user_profile():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### Get_user_profile : payload = ",payload)
    status, retval = eua.Get_user_profile(payload)
    return jsonify(status=status, message=retval)
'''
Cette Api retourne les info d'un user accout identifié par 
son adresse email.
'''
@app.route('/myclass/api/get_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_user_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_user_account : payload = ", payload)
    result, message = eua.get_user_account(payload)
    return jsonify(status=result, message=message)


'''
Cette API créer un compte utilisateur et declenche l'envoi de l'email de notification
'''
@app.route('/myclass/api/add_user_account/', methods=['POST'])
@crossdomain(origin='*')
def add_user_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    result, message = eua.add_user_account(payload)
    return jsonify(status=result, message=message)


'''
Cette API valide une inscription d'un user
'''
@app.route('/myclass/api/valide_user_account/<value>', methods=['GET','POST'])
@crossdomain(origin='*')
def valide_user_account(value):

    print(" ### validation du compte = ",value)
    status, retval = eua.valide_user_account(value)

    url = ""
    if( status ):
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.com/mysy-account-activated/'
        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'http://localhost:3009/mysy-account-activated/'
        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/mysy-account-activated/'

    else:
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.com/erreur'

        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'http://localhost:3009/erreur/'

        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/erreur'

    return  redirect(url)


'''
Cette api met à jour un compte utilisateur
'''
@app.route('/myclass/api/update_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def update_user_account():
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, retval = eua.update_user_account(payload)
    return jsonify(status=status, message=retval)


@app.route('/myclass/api/create_class/', methods=['POST','GET'])
@crossdomain(origin='*')
def create_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.add_class(payload)
    return jsonify(status=status, message=retval)



'''
Cette api recupete et affiche une formation.
la clé d'une formation est le code externe, 
mais pour que l'api fonctionne, il faut lui fournir

- le token du partenaire
'''
@app.route('/myclass/api/get_class/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",str(payload)+"  IP requester = "+str(request.remote_addr))
    status, retval = cm.get_class(payload)
    return jsonify(status=status, message=retval)

"""
Cette API retourne les X formations du meme organisme de formations
associé à une formation données : current_internal_code

limit : X
condition : internal_url != current_internal_code
partner_owner_recid = current_partner_owner_recid

"""
@app.route('/myclass/api/get_associated_class_of_partnair/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_associated_class_of_partnair():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",str(payload)+"  IP requester = "+str(request.remote_addr))
    status, retval = cm.get_associated_class_of_partnair(payload)
    return jsonify(status=status, message=retval)


'''
Cette api recupete la formation d'un partenaire donnée
elle est appelée exclusivement en mode connecté

- le token du partenaire
'''
@app.route('/myclass/api/get_partner_class/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_partner_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_partner_class payload = ",str(payload)+"  IP requester = "+str(request.remote_addr))
    status, retval = cm.get_partner_class(payload)
    return jsonify(status=status, message=retval)

"""
Cette API fait une recherche au sens large avec des like
"""
@app.route('/myclass/api/find_partner_class_like/', methods=['POST','GET'])
@crossdomain(origin='*')
def find_partner_class_like():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### find_partner_class_like payload = ",str(payload)+"  IP requester = "+str(request.remote_addr))
    status, retval = cm.find_partner_class_like(payload)
    return jsonify(status=status, message=retval)




"""
Cette API retourne le code externe de toutes les formations
d'un partenaire 
"""
@app.route('/myclass/api/get_partner_class_external_code/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_partner_class_external_code():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",str(payload)+"  IP requester = "+str(request.remote_addr))
    status, retval = cm.get_partner_class_external_code(payload)
    return jsonify(status=status, message=retval)




@app.route('/myclass/api/update_class/', methods=['POST'])
@crossdomain(origin='*')
def update_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.update_class(payload)
    return jsonify(status=status, message=retval)


'''
deverrouillage  d'une formation  - unlock training

'''
@app.route('/myclass/api/unlock_class/', methods=['POST'])
@crossdomain(origin='*')
def unlock_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.unlock_class(payload)
    return jsonify(status=status, message=retval)

'''
Verrouillage  d'une formation  - lock training
'''
@app.route('/myclass/api/lock_class/', methods=['POST'])
@crossdomain(origin='*')
def lock_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.lock_class(payload)
    return jsonify(status=status, message=retval)


'''
API de Depublication d'une formation
'''
@app.route('/myclass/api/unpublish_class/', methods=['POST'])
@crossdomain(origin='*')
def unpublish_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.unpublish_class(payload)
    return jsonify(status=status, message=retval)


'''
API de Publication d'une formation
'''
@app.route('/myclass/api/pusblish_class/', methods=['POST'])
@crossdomain(origin='*')
def pusblish_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.pusblish_class(payload)
    return jsonify(status=status, message=retval)



'''
Desactivé une formation  - disable training

'''
@app.route('/myclass/api/disable_class/', methods=['POST'])
@crossdomain(origin='*')
def disable_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.disable_class(payload)
    return jsonify(status=status, message=retval)

'''
Reactivation d'une formation  - enable training
'''
@app.route('/myclass/api/enable_class/', methods=['POST'])
@crossdomain(origin='*')
def enable_class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = cm.enable_class(payload)
    return jsonify(status=status, message=retval)




'''
Cette api retourne les formations dont "attribut"="valeur"
'''
@app.route('/myclass/api/get_class_by_name/<attribut>,<value>', methods=['GET','POST'])
@crossdomain(origin='*')
def get_all_class_by_attribut(attribut, value):
    result = wp.get_all_class_by_attribut(attribut, value)
    if result:
        #print(" in main result =  ", result)
        return jsonify(result)

    return jsonify(status="False")


'''
Cette api retourne les formations dont "attribut" IN (list_valeurs)
list_valeurs = val1,val2,val3,...,valn
'''
@app.route('/myclass/api/get_class_by_list_attr/<attribut>;<list_values>', methods=['GET'])
@crossdomain(origin='*')
def get_class_by_list_attr(attribut, list_values):
    print(" ### attribut = "+attribut)

    result = wp.get_class_by_list_attr(attribut, list_values)
    if result:
        #print(" in main result =  ", result)
        return jsonify(result)
    return jsonify(status="False")


'''
fonction actuellement utilisé sur le front : 
Cette fonction "get_recherche_gle_class"  prend en argument une phrase et
retourne les formations associées
'''
@app.route('/myclass/api/get_recherche_gle_class/<sentence>', methods=['GET'])
@crossdomain(origin='*')
def get_recherche_gle_class(sentence):

    result = wp.get_recherche_gle_class(sentence)
    if result:
        #print(" in main result =  ", result)
        return jsonify(result)
    return jsonify(status="False")


'''
Fonction utilisée pour la recherche simple d'un texte.
sans utilisation de critère ni de tag

'''
@app.route('/myclass/api/recherche_text_simple/', methods=['GET','POST'])
@crossdomain(origin='*')
def recherche_text_simple():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    #print(" ### payload = ", payload)
    status, result = wp.recherche_text_simple(payload)
    return jsonify(status=status, message=result)



# recherche globale
'''
fonction NON utilisée sur le front : 
Cette fonction fait une recherche globale en prenant une chaine de caractère  - not use on front
'''
@app.route('/myclass/api/get_class_global_search/<search_string>', methods=['GET','POST'])
@crossdomain(origin='*')
def get_class_global_search(search_string):
    result = cm.get_class_global_search(search_string)
    if result:
        #print(" in main result =  ", result)
        return jsonify(result)

    return jsonify(status="False")


@app.route('/myclass/api/get_all_class/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_all_class():
    payload = request.form.to_dict()
    print(" ### get_all_class : payload = ", payload)
    if mycommon.check_source_ipv4(str(request.remote_addr)) is False :
        return  jsonify(status="False", message="Security check : "+request.remote_addr+"' is not autorized")


    status, result = wp.get_all_class(payload)

    response =  jsonify(status=status, message=result)
    response.headers.add("Access-Control-Allow-Origin", "*")
    response.headers.add("Access-Control-Allow-Headers", "*")
    response.headers.add("Access-Control-Allow-Methods", "*")
    return response



@app.route('/myclass/api/update_class_by_attribut/<objId>,<attribut>,<value>', methods=['GET','POST'])
def update_class_by_attribut(objId, attribut, value):
    print(" update_class_by_attribut ")
    result = wp.update_class_by_attribut(objId, attribut, value)
    if result:
        print(" in main result =  ", result)
        return jsonify(result)

    return jsonify(status="False")

# this function update all fields of class.
# First : we retrieve all field of class and display it.
# Second : the user update some fields but all fields will be returned for update
# it means all field are stored in :
# payload = request.form.to_dict()
@app.route('/myclass/api/update_class_by_id/<id>', methods=['GET','POST'])
def update_class_by_id(id):
    payload = request.form.to_dict()
    print("on va modifier l'id (fourni en input) : ", id)
    for key, value in payload.items():
        print(key," : ", value)

    result = wp.update_class(payload)
    #result = "1"
    if result:
        return jsonify(status='True', message='Class updated')
    return jsonify(status='False')


'''
Cette API créer un compte patenaire / client  et declenche l'envoi de l'email de notification
La clé est reste l'adresse email du partenaire (pas du contact du partenaire)
'''
@app.route('/myclass/api/add_partner_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def add_partner_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.add_partner_account(payload)
    return jsonify(status=status, message=retval)



'''
Cette API valide une inscription d'un partenaire
'''
@app.route('/myclass/api/valide_partnair_account/<value>', methods=['GET','POST'])
@crossdomain(origin='*')
def valide_partnair_account(value):

    print(" ### validation du compte = ",value)
    result, token = pa.valide_partnair_account(value)

    if (result):
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.com/PartnerLogin0/'
        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'http://localhost:3009/PartnerLogin0'
        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/PartnerLogin0/'

    else:
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.com/erreur'
        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'https://www.mysy-training.com/erreur'
        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/erreur'

    return redirect(url)



'''
Cette fonction modifie/MAJ un partenaire
'''
@app.route('/myclass/api/update_partner_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def update_partner_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.update_partner_account(payload)
    return jsonify(status=status, message=retval)



'''
Partenair SECURITY : Cette API  modifie/MAJ le mail du  partenaire
'''
@app.route('/myclass/api/update_partner_main_mail/', methods=['POST','GET'])
@crossdomain(origin='*')
def update_partner_main_mail():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.update_partner_main_mail(payload)
    return jsonify(status=status, message=retval)




'''
Partenair SECURITY : Cette API  modifie/MAJ le password du  partenaire
'''
@app.route('/myclass/api/update_partner_pwd/', methods=['POST','GET'])
@crossdomain(origin='*')
def update_partner_pwd():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.update_partner_pwd(payload)
    return jsonify(status=status, message=retval)


"""
Cette API met à jour la clé d'insertion d'un nouvel collaborateur
"""
@app.route('/myclass/api/update_partner_insert_key/', methods=['POST','GET'])
@crossdomain(origin='*')
def update_partner_insert_key():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.update_partner_insert_key(payload)
    return jsonify(status=status, message=retval)




'''
Cette fonction recupere les données d'un partenaire

'''
@app.route('/myclass/api/get_partner_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_partner_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = pa.get_partner_account(payload)
    return jsonify(status=status, message=retval)



'''
Cette API index la base donnée.
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes()
    return jsonify(status=status, message=retval)


'''
Cette API index la base donnée en se basant sur le title.
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes_title/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes_title():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes_title()
    return jsonify(status=status, message=retval)



'''
Cette API index la base donnée en se basant sur les videos qui ont une transcription
le champs en question sera : "video_text".
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes_video_text/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes_video_text():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes_video_text()
    return jsonify(status=status, message=retval)



''' Analyse Youtubes 
'''
@app.route('/myclass/api/ela_index_all_ytubes_video_transcription/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_ytubes_video_transcription():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = YTA.ela_index_all_ytubes_video_transcription()
    return jsonify(status=status, message=retval)



'''
Cette API index la base donnée en se basant sur le description.
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes_desc/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes_desc():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes_desc()
    return jsonify(status=status, message=retval)



'''
Cette API index la base donnée en se basant sur le objectif.
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes_obj/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes_obj():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes_obj()
    return jsonify(status=status, message=retval)


'''
Cette API index la base donnée en se basant sur les mots clées (keyword).
La fonction "ela_index_all_classes" va aller chercher chaque cours dans la BDD
et créer les mots clées qui sont ensuite enregister dans la table "elaindex" 

'''
@app.route('/myclass/api/ela_index_all_classes_keywords/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_classes_keywords():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_classes_keywords()
    return jsonify(status=status, message=retval)




'''
Cette API, utilisée dans phase de developpement
est utilisé pour supprimer le token d'un user

Use case : Uniquement en developpement
'''
@app.route('/myclass/api/Dev_del_user_token/', methods=['POST','GET'])
@crossdomain(origin='*')
def Dev_del_user_token():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = dev_function.Dev_del_user_token(payload)
    return jsonify(status=status, message=retval)

'''
Recherche en mode tips
'''
@app.route('/myclass/api/recherche_tips/', methods=['POST','GET'])
@crossdomain(origin='*')
def recherche_tips():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = wp.recherche_tips(payload)
    return jsonify(status=status, message=retval)



'''
Recuperation de l'historique de recherche d'un user
'''
@app.route('/myclass/api/get_stored_recherche/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_stored_recherche():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = wp.get_stored_recherche(payload)
    return jsonify(status=status, message=retval)


'''
Cette API met à jour le password d'un user
'''
'''
Recuperation de l'historique de recherche d'un user
'''
@app.route('/myclass/api/change_user_pwd/', methods=['POST','GET'])
@crossdomain(origin='*')
def change_user_pwd():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.change_user_pwd(payload)
    return jsonify(status=status, message=retval)


'''
Cette API met à jour le l'adresse email principale d'un user
'''

@app.route('/myclass/api/change_uer_email/', methods=['POST','GET'])
@crossdomain(origin='*')
def change_uer_email():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.change_uer_email(payload)
    return jsonify(status=status, message=retval)

'''
Cette API supprime un compte utilisateur tout en gardant la cohérence
des information.

Cela revient à :
1 - Anonyser le compte tous les champ identifiants une personne
(['adr_street', 'adr_city', 'adr_zip', 'adr_country', 'mob_phone','link_facebook', 'link_twitter', 'token'])
2 - Bloquer le compte
3 - Desactiver le compte
'''
@app.route('/myclass/api/delete_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def delete_user_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.delete_user_account(payload)
    return jsonify(status=status, message=retval)



'''
Cette API verrouille le compte d'un utilisateur
Cela revient à mettre le champ : "locked" à 1

'''
@app.route('/myclass/api/lock_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def lock_user_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.lock_user_account(payload)
    return jsonify(status=status, message=retval)



'''
Cette API desactive le compte d'un utilisateur
Cela revient à mettre le champ : "active" à 0 et "locked" a 1

'''
@app.route('/myclass/api/desable_user_account/', methods=['POST','GET'])
@crossdomain(origin='*')
def desable_user_account():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = eua.desable_user_account(payload)
    return jsonify(status=status, message=retval)


'''
Cette API enregistre le message d'un utilisateur
Par pour la gestion des message de "contactez-nous".
'''
@app.route('/myclass/api/add_user_message/', methods=['POST','GET'])
@crossdomain(origin='*')
def add_user_message():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = um.add_user_message(payload)
    return jsonify(status=status, message=retval)

'''
Cette API recuperer le message posté par un utilisateur.
Le premier cas d'usage est la recuperation post effectué sur un article par un 
utilisateur
'''
@app.route('/myclass/api/get_user_message/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_user_message():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = um.get_user_message(payload)
    return jsonify(status=status, message=retval)



'''
Cette API ajoute des formation en masse
par exemple avec un fichier CSV
'''

def allowed_file(filename):
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in MYSY_GV.ALLOWED_EXTENSIONS


@app.route('/myclass/api/add_class_mass/', methods=['POST','GET'])
@crossdomain(origin='*')
def add_class_mass():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    print(request.files)

    if request.method == 'POST':
        # Create variable for uploaded file
        f = request.files['File']

        status, retval = cm.add_class_mass(f, app.config['UPLOAD_FOLDER'], payload)

    return jsonify(status=status, message=retval)

'''
Enregistrement d'une image de profil d'un utilisateur
'''
@app.route('/myclass/api/recordImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def recordImage():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    print(request.files)

    if request.method == 'POST':
        # Create variable for uploaded file
        f = request.files['File']

        status= mycommon.recordImage(f, app.config['UPLOAD_FOLDER'], payload)

    return jsonify(status=status)

'''
Test de recuperation d'une image enregistrée
'''

@app.route('/myclass/api/getRecodedImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def getRecodedImage():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### getRecodedImage : payload = ",payload)
    status, myimg= mycommon.getRecodedImage(payload)
    return jsonify(status=status, message=myimg)




'''
Cette API gere la connexion d'un partenaire.

Pour memo la connexion d'un partenaire est differente de celle d'un user
Pour le partenaire, en plud du mail, passwd, il faut fournir le token qui est "secrete"
'''
@app.route('/myclass/api/partner_login/', methods=['POST','GET'])
@crossdomain(origin='*')
def partner_login():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    print(request.files)
    status, retval = pa.partner_login(payload)
    return jsonify(status=status, message=retval)


'''
Cette API recuperer tous les articles et avis sur les formations
'''
@app.route('/myclass/api/get_all_articles_avis/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_all_articles_avis():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = aa.get_all_articles_avis(payload)
    return jsonify(status=status, message=retval)



'''
Cette API recupere un article/avis donné
'''
@app.route('/myclass/api/get_articles_avis/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_articles_avis():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_articles_avis : payload = ",payload)
    status, retval = aa.get_articles_avis(payload)
    return jsonify(status=status, message=retval)

'''
Cette API ajouter un article/avis
'''
@app.route('/myclass/api/add_articles_avis/', methods=['POST','GET'])
@crossdomain(origin='*')
def add_articles_avis():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = aa.add_articles_avis(payload)
    return jsonify(status=status, message=retval)


'''
Cette API indexe les articles et avis postés
'''

@app.route('/myclass/api/ela_index_all_articles_avis/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_all_articles_avis():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_all_articles_avis()
    return jsonify(status=status, message=retval)


''' 
Cette API recherche un articles ou un avis en se basant sur le
titre de la formation'''
@app.route('/myclass/api/recherche_articles_avis/', methods=['GET','POST'])
@crossdomain(origin='*')
def recherche_articles_avis():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = aa.recherche_articles_avis(payload)
    return jsonify(status=status, message=result)


''' 
Cette API retourne les articles et avis à la Une'''
@app.route('/myclass/api/get_article_avis_alaune/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_article_avis_alaune():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = aa.get_article_avis_alaune(payload)
    return jsonify(status=status, message=result)


'''
Cette API reinitialise le mot de passe d'un utilisation
depuis le front office'''
@app.route('/myclass/api/InitUserPasswd/', methods=['GET','POST'])
@crossdomain(origin='*')
def InitUserPasswd():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = eua.InitUserPasswd(payload)
    return jsonify(status=status, message=result)

'''
Cette API verifie la validité d'un token 
'''
@app.route('/myclass/api/IsUserTokenValide/', methods=['GET','POST'])
@crossdomain(origin='*')
def IsUserTokenValide():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = eua.IsUserTokenValide(payload)
    return jsonify(status=status, message=result)

'''
Cette API, modifie le pwd d'un user
en partant d'un token.
l'api est utilisé dans le cas d'un process de reinitialisation du pwd
par le user meme'''
@app.route('/myclass/api/Reset_user_pwd_by_token/', methods=['GET','POST'])
@crossdomain(origin='*')
def Reset_user_pwd_by_token():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = eua.Reset_user_pwd_by_token(payload)
    return jsonify(status=status, message=result)



'''
Cette API envoi l'email de suppression du compte utilisateur.
une suppression se passe tjrs 2 phase : 
pahse 1 : envoi de l'email + blocage du compte
pahse 2 : confirmation depuis l'email recu.
'''
@app.route('/myclass/api/send_mail_delete_user/', methods=['GET','POST'])
@crossdomain(origin='*')
def send_mail_delete_user():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = eua.send_mail_delete_user(payload)
    return jsonify(status=status, message=result)


'''
Cette API pour des tests perso
'''
@app.route('/myclass/api/mysy_recherche_levenshtein_orig/', methods=['GET','POST'])
@crossdomain(origin='*')
def mysy_recherche_levenshtein_orig():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = TP.mysy_recherche_levenshtein_orig()
    return jsonify(status=status, message=result)

'''
Cette API est le cron qui traite les emails stockes dans la collection
'user_message'
'''
@app.route('/myclass/api/CronUSerMessage_Mail/', methods=['GET','POST'])
@crossdomain(origin='*')
def CronUSerMessage_Mail():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, date_treatment, result = mycommon.CronUSerMessage_Mail()
    return jsonify(status=status, date_treatment = str(date_treatment), message=result)

'''
Juste une API pour tester de ptite choses
'''
@app.route('/myclass/api/OrderClassRandomly/', methods=['GET','POST'])
@crossdomain(origin='*')
def OrderClassRandomly():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = mycommon.FormationAlaUne()
    return jsonify(status=status,  message=result)


@app.route('/myclass/api/Migration_internal_url/', methods=['GET','POST'])
@crossdomain(origin='*')
def Migration_internal_url():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = "none", "none", #mycommon.Migration_internal_url()
    return jsonify(status=status,  message=result)


'''
Correction erreur title mymooc.com
'''
@app.route('/myclass/api/Migration_mooc_title/', methods=['GET','POST'])
@crossdomain(origin='*')
def Migration_mooc_title():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = "none", "none", #mycommon.Migration_mooc_title()
    return jsonify(status=status,  message=result)



'''
Cette API va aller chercher dans la collection "elaindex" 
les mots qui contiennent le mot "mot"'''
@app.route('/myclass/api/GetMotFromElaIndex/', methods=['GET','POST'])
@crossdomain(origin='*')
def GetMotFromElaIndex():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = mycommon.GetMotFromElaIndex(payload)
    return jsonify(status=status,  message=result)

'''
Cette API retour une formation "coup de coeur" apres
avoir effectué tous les controles
'''
@app.route('/myclass/api/get_class_coup_de_coeur/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_class_coup_de_coeur():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = cm.get_class_coup_de_coeur(payload)
    return jsonify(status=status,  message=result)


"""
Cette API clean la collecion "elaindex" 
"""
@app.route('/myclass/api/clean_ElaIndex/', methods=['GET','POST'])
@crossdomain(origin='*')
def clean_ElaIndex():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = mycommon.clean_ElaIndex()
    return jsonify(status=status,  message=result)


"""
Cette API clean les internal url de la collection "myclass" 
"""
@app.route('/myclass/api/clean_internal_url/', methods=['GET','POST'])
@crossdomain(origin='*')
def clean_internal_url():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = mycommon.clean_internal_url()
    return jsonify(status=status,  message=result)



'''
Cette API retourne les formations par metier
'''
@app.route('/myclass/api/get_class_by_metier/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_class_by_metier():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = cm.get_class_by_metier(payload)
    return jsonify(status=status, message=result)


'''
Cette API met à jour les formations en ajoutant les metier
'''
@app.route('/myclass/api/UpdateMetier/', methods=['GET','POST'])
@crossdomain(origin='*')
def UpdateMetier():
    status = mycommon.UpdateMetier()
    return jsonify(status=status)



'''
Cette API effectue la migration d'un compte utilisateur 
vers un compte pro (ou compte partenaire)
'''
@app.route('/myclass/api/UpgradetoPro/', methods=['GET','POST'])
@crossdomain(origin='*')
def UpgradetoPro():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = pa.UpgradetoPro(payload)
    return jsonify(status=status,  message=result)



'''
Cette API recupere les facture d'un client en prenant son tokek
'''
@app.route('/myclass/api/get_invoice_by_customer/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_invoice_by_customer():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = invoice.get_invoice_by_customer(payload)
    return jsonify(status=status,  message=result)

'''
Cette API recupere les produits et services d'un pack données.
Si le pack n'est pas defini, alors tous les produits valides sont
retournés
'''
@app.route('/myclass/api/get_product_service/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_product_service():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = PS.get_product_service(payload)
    return jsonify(status=status,  message=result)


"""
Cette API rengristre un mode depayment (CB ou SEPA) 
"""
@app.route('/myclass/api/add_payement_mode/', methods=['GET','POST'])
@crossdomain(origin='*')
def add_payement_mode():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = invoice.add_payement_mode(payload)
    return jsonify(status=status,  message=result)


"""
Cette API recupere le mode de payement par defaut d'un client
"""
@app.route('/myclass/api/get_payement_mode/', methods=['GET','POST'])
@crossdomain(origin='*')
def get_payement_mode():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", payload)
    status, result = invoice.get_payement_mode(payload)
    return jsonify(status=status,  message=result)

"""
Cette API recupere les données et crée la commande
"""
@app.route('/myclass/api/createOrder/', methods=['GET','POST'])
@crossdomain(origin='*')
def createOrder():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message, order_id = invoice.createOrder(payload)
    return jsonify(status=status,  message=message, order_id=order_id)

"""
Cette API retourne la liste des mots suggerés pour la recherche
"""
@app.route('/myclass/api/Get_Suggested_Word/', methods=['GET','POST'])
@crossdomain(origin='*')
def Get_Suggested_Word():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = mycommon.Get_Suggested_Word()
    return jsonify(status=status,  message=message)


"""
Cette API retourne la liste des villes de la france suggerés pour la recherche
"""
@app.route('/myclass/api/Get_Suggested_Fr_Cities/', methods=['GET','POST'])
@crossdomain(origin='*')
def Get_Suggested_Fr_Cities():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### Get_Suggested_Fr_Cities : payload = ", str(payload))
    status, message = mycommon.Get_Suggested_Fr_Cities()
    return jsonify(status=status,  message=message)


"""
Cette API imprime et envoie les factures aux clients
"""
@app.route('/myclass/api/PrintAndSendInvoices/', methods=['GET','POST'])
@crossdomain(origin='*')
def PrintAndSendInvoices():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = factures.PrintAndSendInvoices()
    return jsonify(status=status,  message=message)


"""
Cette API imprime et envoie les factures aux clients
"""
@app.route('/myclass/api/PutClassNote/', methods=['GET','POST'])
@crossdomain(origin='*')
def PutClassNote():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = mycommon.PutClassNote()
    return jsonify(status=status,  message=message)

"""
Cette API envoie la facture d'un client
"""

@app.route('/myclass/api/GetCustomerInvoice/<token>/<invoiceid>', methods=['GET','POST'])
@crossdomain(origin='*')
def GetCustomerInvoice(invoiceid, token):
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = {}
    payload['token'] = str(token)
    payload['invoiceid'] = str(invoiceid)
    print(" ### payload facture = ", str(invoiceid), " token = ",str(token))
    return factures.GetCustomerInvoice(payload)

"""
API de facturation automatique des commandes 
"""
@app.route('/myclass/api/AutoamticCreateInvoice/', methods=['GET','POST'])
@crossdomain(origin='*')
def AutoamticCreateInvoice():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = factures.AutoamticCreateInvoice()
    return jsonify(status=status,  message=message)

"""
API de excuter une fonction de statistique
"""
@app.route('/myclass/api/GetStat_class_view_old/', methods=['GET','POST'])
@crossdomain(origin='*')
def GetStat_class_view_old():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.GetStat_class_view_old()
    return jsonify(status=status,  message=message)


"""
API de excuter une fonction de statistique sur la semaine ecoulée
"""
@app.route('/myclass/api/GetStat_class_view/', methods=['GET','POST'])
@crossdomain(origin='*')
def GetStat_class_view():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.GetStat_class_view(payload)
    return jsonify(status=status,  message=message)



"""
Cette API retourne les STAT des X formations les plus vues d'un client donné sur 
une periode donnée
"""
@app.route('/myclass/api/GetStat_class_view_topX/', methods=['GET','POST'])
@crossdomain(origin='*')
def GetStat_class_view_topX():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.GetStat_class_view_topX(payload)
    return jsonify(status=status,  message=message)



"""
Cette API retourne les X formations les plus vues d'un client donné sur 
une periode donnée
"""
@app.route('/myclass/api/Get_X_Best_Class_On_Given_period/', methods=['GET','POST'])
@crossdomain(origin='*')
def Get_X_Best_Class_On_Given_period():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.Get_X_Best_Class_On_Given_period(payload)
    return jsonify(status=status,  message=message)


"""
Cette API retour les statistiques d'une formation données
"""
@app.route('/myclass/api/GetStat_class_by_internal_url/', methods=['GET','POST'])
@crossdomain(origin='*')
def GetStat_class_by_internal_url():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.GetStat_class_by_internal_url(payload)
    return jsonify(status=status,  message=message)


@app.route('/myclass/api/test_return/', methods=['GET','POST'])
@crossdomain(origin='*')
def test_return():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = Stat.test_return()
    return jsonify(status=status,  message=message)


"""
API de suppression du compte de LS"""
@app.route('/myclass/api/removeLSaccount/', methods=['GET','POST'])
@crossdomain(origin='*')
def removeLSaccount():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ", str(payload))
    status, message = mycommon.removeLSaccount()
    return jsonify(status=status,  message=message)


"""
Pour des test, et seulement pour les test
cette fonction permet de mettre les formation du user "ls" 
en première page.

Cette fonction doit etre inactive en production 
"""
@app.route('/myclass/api/PutLSClassFirst/', methods=['GET','POST'])
@crossdomain(origin='*')
def PutLSClassFirst():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### PutLSClassFirst : payload = ", str(payload))
    status, message = mycommon.PutLSClassFirst()
    return jsonify(status=status,  message=message)


"""
Correction data - api oneshot
"""
@app.route('/myclass/api/correction_collection/', methods=['GET','POST'])
@crossdomain(origin='*')
def correction_collection():
    # On recupere le corps (payload) de la requete
    print(" correction_collection ")
    status, message = mycommon.correction_collection()
    return jsonify(status=status,  message=message)



"""
Cette API recuperer l'image de profil d'une formation
"""
@app.route('/myclass/api/getRecodedClassImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def getRecodedClassImage():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### getRecodedClassImage payload = ",payload)
    status, myimg= mycommon.getRecodedClassImage(payload)
    return jsonify(status=status, message=myimg)

"""
Cette API supprimer une l'image de profil d'une formation
"""
@app.route('/myclass/api/DeleteRecodedClassImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def DeleteRecodedClassImage():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### DeleteRecodedClassImage payload = ",payload)
    status, message= mycommon.DeleteRecodedClassImage(payload)
    return jsonify(status=status, message=message)

"""
Cette API de Recuperation d'une image de profils d'une formation pour le mode non connecté. c'est a dire depuis le front
"""
@app.route('/myclass/api/getRecodedClassImage_from_front/', methods=['POST','GET'])
@crossdomain(origin='*')
def getRecodedClassImage_from_front():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, myimg= mycommon.getRecodedClassImage_from_front(payload)
    return jsonify(status=status, message=myimg)



'''
Enregistrement d'une image de profil d'une formation
'''
@app.route('/myclass/api/recordClassImage/', methods=['POST','GET'])
@crossdomain(origin='*')
def recordClassImage():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    print(request.files)

    if request.method == 'POST':
        # Create variable for uploaded file
        f = request.files['File']

        status, message = mycommon.recordClassImage(f, app.config['UPLOAD_FOLDER'], payload)
    return  jsonify(status=status, message=message)


"""
Indexation du titre : Cette API va indexer une formation donnée ou toutes les formation d'un partenaire.
Pour ce faire elle prend en argument : 
- internal_url 
- partenaire_recid
"""
@app.route('/myclass/api/ela_index_given_classes_title/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_given_classes_title():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_given_classes_title(payload)
    return jsonify(status=status, message=retval)


"""
Indexation des mots clés : Cette API va indexer une formation donnée ou toutes les formation d'un partenaire.
Pour ce faire elle prend en argument : 
- internal_url 
- partenaire_recid
"""
@app.route('/myclass/api/ela_index_given_classes_keywords/', methods=['POST','GET'])
@crossdomain(origin='*')
def ela_index_given_classes_keywords():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### payload = ",payload)
    status, retval = ela_index_class.ela_index_given_classes_keywords(payload)
    return jsonify(status=status, message=retval)


"""
Stripe Payement : Creation d'un abonnement
"""
@app.route('/myclass/api/create-subscription/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_create_subscription():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### strip_create_subscription : payload = ",payload)
    localStatus, subscription_id, payment_intent_client_secret = Stripe.create_subscription(payload)

    print(" ### subscription_id = "+str(subscription_id)+"  -- payment_intent_client_secret = "+str(payment_intent_client_secret))
    return jsonify(status=localStatus, subscription_id=subscription_id,payment_intent_client_secret = payment_intent_client_secret )

"""
Stripe Payement : Creation d'un client dans Stripe
"""
@app.route('/myclass/api/create-create_customer/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_create_customer():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### strip_create_customer : payload = ",payload)
    localStatus, stripe_client_id, payment_intent_client_secret = Stripe.create_customer(payload)
    return jsonify(status=localStatus, stripe_client_id=stripe_client_id )


"""
Stripe Payement : Recuperation des methodes de payement d'un client
"""
@app.route('/myclass/api/get_customer_payement_cards/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_get_customer_payement_cards():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### strip_create_customer : payload = ",payload)
    localStatus= Stripe.get_customer_payement_cards(payload)
    return jsonify(status=localStatus,  )

"""
Stripe Payement : Creation d'une carte bancaire
"""
@app.route('/myclass/api/create_payment_card/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_create_payment_card():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### create_payment_card : payload = ",payload)
    localStatus= Stripe.create_update_payment_card(payload)
    return jsonify(status=localStatus,  )


"""
Stripe Payement : Confirmation d'un payement 
"""
@app.route('/myclass/api/confirm_payment/', methods=['POST','GET'])
@crossdomain(origin='*')
def strip_confirm_payment():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### create_payment_card : payload = ",payload)
    localStatus, payement_id, payement_status= Stripe.confirm_suscription(payload)
    return jsonify(status=localStatus, payement_id=payement_id, payement_status=payement_status )


"""
API de gestion des stagiaires à une une formation / Gestion des insciptions
Ajout d'un stagiaire
"""
@app.route('/myclass/api/AddStagiairetoClass/', methods=['POST','GET'])
@crossdomain(origin='*')
def AddStagiairetoClass():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### AddStagiairetoClass : payload = ",payload)
    localStatus, message= inscription.AddStagiairetoClass(payload)
    return jsonify(status=localStatus, message=message )

"""
API de mise à jour d'un stagaire
"""
@app.route('/myclass/api/UpdateStagiairetoClass/', methods=['POST','GET'])
@crossdomain(origin='*')
def UpdateStagiairetoClass():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### UpdateStagiairetoClass : payload = ",payload)
    localStatus, message= inscription.UpdateStagiairetoClass(payload)
    return jsonify(status=localStatus, message=message )


"""
API de recuperation des infos d'un stagiaire
"""
@app.route('/myclass/api/GetStagiaire/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetStagiaire():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetStagiaire : payload = ",payload)
    localStatus, message= inscription.GetStagiaire(payload)
    return jsonify(status=localStatus, message=message )


"""
API de recuperation de la liste de tous les stagaires d'une formation
"""
@app.route('/myclass/api/GetAllClassStagiaire/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetAllClassStagiaire():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetAllClassStagiaire : payload = ",payload)
    localStatus, message= inscription.GetAllClassStagiaire(payload)
    return jsonify(status=localStatus, message=message )


"""
Cette API Crée la liste d'emargement
"""
@app.route('/myclass/api/CreateTableauEmargement/', methods=['POST','GET'])
@crossdomain(origin='*')
def CreateTableauEmargement():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### CreateTableauEmargement : payload = ",str(payload))
    localStatus, message= emargement.CreateTableauEmargement(payload)
    return jsonify(status=localStatus, message=message )

"""
API de recuperation du tableau d'emargement d'un session de formation
"""
@app.route('/myclass/api/GetTableauEmargement/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetTableauEmargement():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetTableauEmargement : payload = ",payload)
    localStatus, message= emargement.GetTableauEmargement(payload)
    return jsonify(status=localStatus, message=message )

"""
API de mise à jour de l'emargement d'une personne
"""
@app.route('/myclass/api/UpdateUserEmargementDate/', methods=['POST','GET'])
@crossdomain(origin='*')
def UpdateUserEmargementDate():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### UpdateUserEmargementDate : payload = ",str(payload))
    localStatus, message= emargement.UpdateUserEmargementDate(payload)
    return jsonify(status=localStatus, message=message )


"""
API de creation d'une session de formation
"""
@app.route('/myclass/api/Add_Update_SessionFormation/', methods=['POST','GET'])
@crossdomain(origin='*')
def Add_Update_SessionFormation():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### Add_Update_SessionFormation : payload = ",str(payload))
    localStatus, message= SF.Add_Update_SessionFormation(payload)
    return jsonify(status=localStatus, message=message )

"""
API de recuperation de toutes les sessions de formation valides et actives
"""
@app.route('/myclass/api/GetActiveSessionFormation_List/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetActiveSessionFormation_List():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetActiveSessionFormation_List : payload = ",str(payload))
    localStatus, message= SF.GetActiveSessionFormation_List(payload)
    return jsonify(status=localStatus, message=message )


"""
API de toutes sessions de formation valide, (peu importe qu'elles soient terminées ou pas
"""
@app.route('/myclass/api/GetAllValideSessionFormation_List/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetAllValideSessionFormation_List():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetAllValideSessionFormation_List : payload = ",str(payload))
    localStatus, message= SF.GetAllValideSessionFormation_List(payload)
    return jsonify(status=localStatus, message=message )



"""
API de recuperation session de formation
"""
@app.route('/myclass/api/GetSessionFormation/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetSessionFormation():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetSessionFormation : payload = ",str(payload))
    localStatus, message= SF.GetSessionFormation(payload)
    return jsonify(status=localStatus, message=message )

"""
API de generation de liste PDF des liste d'emargement
"""
@app.route('/myclass/api/GerneratePDFEmargementList/<token>/<session_id>/<internal_url>', methods=['POST','GET'])
@crossdomain(origin='*')
def GerneratePDFEmargementList(token, session_id, internal_url):
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = {}
    payload['token'] = str(token)
    payload['session_id'] = str(session_id)
    payload['class_internal_url'] = str(internal_url)

    print(" ### GerneratePDFEmargementList : payload = ",str(payload))



    localStatus, response= emargement.GerneratePDFEmargementList(payload)
    if(localStatus ):
        return response
    else:
        return False



"""
API d'Envoie de l'email de confirmation de l'inscription 
"""
@app.route('/myclass/api/SendInscriptionConfirmation/', methods=['POST','GET'])
@crossdomain(origin='*')
def SendInscriptionConfirmation():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### incription_training_confirmation_mail : payload = ",str(payload))
    localStatus, message= inscription.SendInscriptionConfirmation(payload)
    return jsonify(status=localStatus, message=message )

"""
API d'Envoie de l'email de pre-inscription à une formation 
"""
@app.route('/myclass/api/SendPre_InscriptionEmail/', methods=['POST','GET'])
@crossdomain(origin='*')
def SendPre_InscriptionEmail():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### SendPre_InscriptionEmail : payload = ",str(payload))
    localStatus, message= inscription.SendPre_InscriptionEmail(payload)
    return jsonify(status=localStatus, message=message )



"""
API pour tester les nice emails de cherif (alternative à sendinblu)
"""
@app.route('/myclass/api/MysyGenericEmail_tpl/', methods=['POST','GET'])
@crossdomain(origin='*')
def MysyGenericEmail_tpl():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### MysyGenericEmail : payload = ",str(payload))
    localStatus, message= emails.MysyGenericEmail_tpl()
    return jsonify(status=localStatus, message=message )

@app.route('/myclass/api/MysyOrderEmail_tpl/', methods=['POST','GET'])
@crossdomain(origin='*')
def MysyOrderEmail_tpl():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### MysyOrderEmail_tpl : payload = ",str(payload))
    localStatus, message= emails.MysyOrderEmail_tpl()
    return jsonify(status=localStatus, message=message )



"""
API de recuperation de liste de OPCO
"""
@app.route('/myclass/api/GetListOpco/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetListOpco():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetListOpco : payload = ",str(payload))
    localStatus, message= opco.GetListOpco()
    return jsonify(status=localStatus, message=message )


"""
API de demande d'information sur une formation
"""
@app.route('/myclass/api/RenseignementClass/', methods=['POST','GET'])
@crossdomain(origin='*')
def RenseignementClass():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### RenseignementClass : payload = ",str(payload))
    localStatus, message= cm.RenseignementClass(payload)
    return jsonify(status=localStatus, message=message )

"""
API d'envoi de la liste d'emargement
"""
@app.route('/myclass/api/EmargementMail/', methods=['POST','GET'])
@crossdomain(origin='*')
def EmargementMail():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### EmargementMail : payload = ",str(payload))
    localStatus, message= emails.SendEmargementMail(payload)
    return jsonify(status=localStatus, message=message )



"""
Cette API permet de faire l'emargement par un utilisateur
"""
@app.route('/myclass/api/UserEmargementValidation/<value>/<session>', methods=['GET','POST'])
@crossdomain(origin='*')
def UserEmargementValidation(value, session):

    print(" ### UserEmargementValidation value = "+str(value)+" session =  "+str(session))
    diction = {'value':str(value), 'session':str(session)}
    status, message = mycommon.UserEmargementValidation(diction)

    url = ""

    if( status ):
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.comEmargement/'
        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'http://localhost:3009/Emargement/'
        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/Emargement/'

    else:
        if (MYSY_GV.MYSY_ENV == "PROD"):
            url = 'https://www.mysy-training.com/erreur'

        elif (MYSY_GV.MYSY_ENV == "DEV"):
            url = 'http://localhost:3009/erreur/'

        elif (MYSY_GV.MYSY_ENV == "REC"):
            url = 'https://dev.mysy-training.com/erreur'

    return  redirect(url)

"""
API d'envoi d'une facture manuelle avec RIB
"""
@app.route('/myclass/api/ManualSendInvoiceEmailRIB/', methods=['POST','GET'])
@crossdomain(origin='*')
def ManualSendInvoiceEmailRIB():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### EmargementMail : payload = ",str(payload))
    localStatus, message= emails.ManualSendInvoiceEmailRIB(payload)
    return jsonify(status=localStatus, message=message )

"""
API de recuperation au formation CSV de la liste des inscrits à une formation
avec les statuts (validé ou pas)
"""
@app.route('/myclass/api/DownloadParticipantsList/<token>/<sessionid>', methods=['GET','POST'])
@crossdomain(origin='*')
def DownloadParticipantsList(sessionid, token):
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = {}
    payload['token'] = str(token)
    payload['session_id'] = str(sessionid)
    print(" ### DownloadParticipantsList payload facture = ", str(payload))
    local_status, local_file =  inscription.DownloadParticipantsList(payload)
    if( local_status is False ):
        return ""

    return local_file


"""
API d'import des stagaires en masse avec un fichier csv
"""

@app.route('/myclass/api/AddStagiairetoClass_mass/', methods=['POST','GET'])
@crossdomain(origin='*')
def AddStagiairetoClass_mass():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### AddStagiairetoClass_mass payload = ",payload)
    #print(request.files)

    if request.method == 'POST':
        # Create variable for uploaded file
        f = request.files['File']
        localStatus, message = inscription.AddStagiairetoClass_mass(f, app.config['UPLOAD_FOLDER'], payload)
        #status, retval = cm.add_class_mass(f, app.config['UPLOAD_FOLDER'], payload)

        return jsonify(status=localStatus, message=message)


""" 
API d'import en masse des sessions de formation
"""
@app.route('/myclass/api/Add_Update_SessionFormation_mass/', methods=['POST','GET'])
@crossdomain(origin='*')
def Add_Update_SessionFormation_mass():

# On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### Add_Update_SessionFormation_mass payload = ",payload)
    #print(request.files)

    if request.method == 'POST':
        # Create variable for uploaded file
        f = request.files['File']
        localStatus, message = SF.Add_Update_SessionFormation_mass(f, app.config['UPLOAD_FOLDER'], payload)
        #status, retval = cm.add_class_mass(f, app.config['UPLOAD_FOLDER'], payload)

        return jsonify(status=localStatus, message=message)


"""
API de recuperation des infos detaillées d'un stagiaire pour une session
"""

@app.route('/myclass/api/GetAttendeeDetail_perSession/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetAttendeeDetail_perSession():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetAttendeeDetail_perSession : payload = ",str(payload))
    localStatus, message= mycommon.GetAttendeeDetail_perSession(payload)
    return jsonify(status=localStatus, message=message )


"""
API de recuperation, de liste des attestions et certificats
"""
@app.route('/myclass/api/GetPartnerAttestation_Certificat/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetPartnerAttestation_Certificat():
    # On recupere le corps (payload) de la requet
    payload = request.form.to_dict()
    print(" ### GetPartnerAttestation_Certificat : payload = ",str(payload))
    localStatus, message= Att_Cert.GetPartnerAttestation_Certificat(payload)
    return jsonify(status=localStatus, message=message )

"""
API de recuperation des données d'une attestation
"""
@app.route('/myclass/api/GetSpecificPartnerAttestation_Certificat/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetSpecificPartnerAttestation_Certificat():
    # On recupere le corps (payload) de la requet
    payload = request.form.to_dict()
    print(" ### GetSpecificPartnerAttestation_Certificat : payload = ",str(payload))
    localStatus, message= Att_Cert.GetSpecificPartnerAttestation_Certificat(payload)
    return jsonify(status=localStatus, message=message )


"""
Cette API genere la fiche de presence d'un stagaire
"""
"""
API de generation de liste PDF des liste d'emargement
"""
@app.route('/myclass/api/PrintAttendeeDetail_perSession/<token>/<session_id>/<attendee_email>', methods=['POST','GET'])
@crossdomain(origin='*')
def PrintAttendeeDetail_perSession(token, session_id, attendee_email):
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = {}
    payload['token'] = str(token)
    payload['session_id'] = str(session_id)
    payload['attendee_email'] = str(attendee_email)
    print(" ### PrintAttendeeDetail_perSession : payload = ",str(payload))

    localStatus, response= inscription.PrintAttendeeDetail_perSession(payload)
    if(localStatus ):
        return response
    else:
        return False


""" API de verification du token d'evaluation 
"""
@app.route('/myclass/api/MySyckeckEvaluationToken/', methods=['POST','GET'])
@crossdomain(origin='*')
def MySyckeckEvaluationToken():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### ckeckEvaluationToken : payload = ",payload)
    localStatus, message= inscription.MySyckeckEvaluationToken(payload)
    return jsonify(status=localStatus, message=message )

"""
API d'evaluation d'une formation
"""
@app.route('/myclass/api/Evaluation_Class/', methods=['POST','GET'])
@crossdomain(origin='*')
def Evaluation_Class():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### Evaluation_Class : payload = ",payload)
    localStatus, message= inscription.Evaluation_Class(payload)
    return jsonify(status=localStatus, message=message )

"""
API Qui declenche l'envoi de l'email d'evaluation d'une formation
"""
@app.route('/myclass/api/SendTrainingEvaluationEmail/', methods=['POST','GET'])
@crossdomain(origin='*')
def SendTrainingEvaluationEmail():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### SendTrainingEvaluationEmail : payload = ",payload)
    localStatus, message= inscription.SendTrainingEvaluationEmail(payload)
    return jsonify(status=localStatus, message=message )

"""
API Qui declenche l'envoi de l'attestation de formation par email
"""
@app.route('/myclass/api/SendAttendeeCertification/', methods=['POST','GET'])
@crossdomain(origin='*')
def SendAttendeeCertification():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### SendAttendeeCertification : payload = ",payload)
    localStatus, message= inscription.SendAttendeeCertification(payload)
    return jsonify(status=localStatus, message=message )

"""
API qui imprime l'attestation de formation d'un participant
"""
@app.route('/myclass/api/PrintAttendeeCertification/<token>/<session_id>/<attendee_email>', methods=['POST','GET'])
@crossdomain(origin='*')
def PrintAttendeeCertification(token, session_id, attendee_email):
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    payload = {}
    payload['token'] = str(token)
    payload['session_id'] = str(session_id)
    payload['attendee_email'] = str(attendee_email)
    print(" ### PrintAttendeeCertification : payload = ", str(payload))

    localStatus, response = inscription.PrintAttendeeCertification(payload)
    if (localStatus):
        return response
    else:
        return False


"""
Cette API retourne la liste des evalutions d'une session de formation
"""
@app.route('/myclass/api/GetListEvaluation_Session/', methods=['POST','GET'])
@crossdomain(origin='*')
def GetListEvaluation_Session():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### GetListEvaluation_Session : payload = ",payload)
    localStatus, message= inscription.GetListEvaluation_Session(payload)
    return jsonify(status=localStatus, message=message )


"""
API de recuperation de liste des liste_domaine_metier
"""
@app.route('/myclass/api/get_List_domaine_formation/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_List_domaine_formation():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_List_domaine_formation : payload = ",str(payload))
    localStatus, message= mycommon.get_List_domaine_formation()
    return jsonify(status=localStatus, message=message )


"""
Recuperation de la liste des domaines et metier 
"""
@app.route('/myclass/api/get_List_domaine_metier/', methods=['POST','GET'])
@crossdomain(origin='*')
def get_List_domaine_metier():
    # On recupere le corps (payload) de la requete
    payload = request.form.to_dict()
    print(" ### get_List_domaine_metier : payload = ",str(payload))
    localStatus, message= mycommon.get_List_domaine_metier()
    return jsonify(status=localStatus, message=message )

if __name__ == '__main__':
    print(" debut api")
    context = SSL.Context(SSL.SSLv23_METHOD)
    if (MYSY_GV.MYSY_ENV == "PROD"):
        mycommon.myprint(" ++++  ENVIRONNEMENT PRODUCTION ++++ ")
        mycommon.myprint("++ DATABASE "+MYSY_GV.CONNECTION_STRING+" ++")
        mycommon.myprint("++ DBNAME " + str(MYSY_GV.dbname) + " ++")
        mycommon.myprint("++ FLASK PORT " + str(MYSY_GV.MYSY_PORT_PROD) + " ++")
        app.run(host='localhost', port=MYSY_GV.MYSY_PORT_PROD, debug=True, threaded=True)

    elif (MYSY_GV.MYSY_ENV == "DEV"):
        mycommon.myprint(" ++++ ENVIRONNEMENT DEVELOPPEMENT ++++")
        mycommon.myprint("++ DATABASE " + MYSY_GV.CONNECTION_STRING + " ++")
        mycommon.myprint("++ DBNAME " + str(MYSY_GV.dbname) + " ++")
        mycommon.myprint("++ FLASK PORT " + str(MYSY_GV.MYSY_PORT_DEV) + " ++")
        app.run(host='localhost', port=MYSY_GV.MYSY_PORT_DEV, debug=True, threaded=True)

    elif (MYSY_GV.MYSY_ENV == "REC"):
        mycommon.myprint(" ++++ ENVIRONNEMENT DEVELOPPEMENT ++++")
        mycommon.myprint("++ DATABASE " + MYSY_GV.CONNECTION_STRING + " ++")
        mycommon.myprint("++ DBNAME " + str(MYSY_GV.dbname) + " ++")
        mycommon.myprint("++ FLASK PORT " + str(MYSY_GV.MYSY_PORT_REC) + " ++")
        app.run(host='localhost', port=MYSY_GV.MYSY_PORT_REC, debug=True, threaded=True)



