Ejemplo n.º 1
0
    def cree_compte_agent(self, valeur):
        if User.trouver_id('agent', valeur["id"]) is False:
            cnx = connexion()
            cursor = cnx.cursor()
            if type(valeur) is type(dict()):
                # logging.debug("inside dict")
                id = valeur["id"]
                nom = valeur["nom"]
                prenom = valeur["prenom"]
                mail = valeur["mail"]
                tel = valeur["tel"]
                debut_contrat = str(date.today())

                ajout_client = (
                    "INSERT INTO `agent` (`ID`, `NOM`, `PRENOM`, `TYPE_USER`, `MAIL`,"
                    " `TEL`, `DEBUT_CONTRAT`) VALUES  ( %s, %s, %s, %s, %s, %s, %s)"
                )
                demande_client = (id, nom, prenom, 'AGENT', mail, tel,
                                  debut_contrat)
                logging.debug(ajout_client + str(demande_client))

            try:
                cnx = connexion()
                cursor = cnx.cursor()
                cursor.execute(ajout_client, demande_client)
                cnx.commit()
                logging.info("insertion réussi")
            except Exception as e:
                logging.warning("Erreur insertion", e)
            finally:
                cnx.close()
        else:
            logging.warning("L'Agent  Existe déjà ")
Ejemplo n.º 2
0
    def validation_Crea(
            self, objet_demandecrea,
            valid_crea: bool):  # Validation création d'ouverture de compte
        objet_demandecrea.validation(valid_crea)
        logging.debug(objet_demandecrea)
        if objet_demandecrea.valid is True:  # Si la demande est validé, création du compte, envoi un mail avec login/mdp + mis en True
            # TODO envoi de mail avec id/mdp
            objet_demandecrea.creation_compte_client()
            cnx = connexion()
            cursor = cnx.cursor()
            password = self.creation_mdp()
            param = (
                "INSERT INTO `login` (`ID`, `Password`, `TYPE_USER`) VALUES (%s,%s,%s)"
            )
            val = (objet_demandecrea.id, password, "CLIENT")
            cursor.execute(param, val)
            cnx.commit()
            cnx.close()
            Compte.creation_compteban(
                objet_demandecrea.id)  # Création compte banquaire

        elif objet_demandecrea.valid is False:  # Si la demande n'est pas valider = envoi de mail demande info + mis en False
            pass  # TODO envoi de mail avec une demande d'info supplementaire
        else:  # Erreur
            print("Erreur/En attente")
Ejemplo n.º 3
0
    def cree_compte_agent(self, valeur):
        cnx = connexion()
        cursor = cnx.cursor()
        if type(valeur) == type(dict()):
            logging.debug("inside dict")
            id = valeur["id"]
            nom = valeur["nom"]
            prenom = valeur["prenom"]
            mail = valeur["mail"]
            tel = valeur["tel"]
            debut_contrat = datetime.date.today()
            logging.debug(debut_contrat)

            ajout_clien = (
                "INSERT INTO agent (ID, NOM, PRENOM, MAIL, TEL, DEBUT_CONTRAT)"
                "VALUES ( %s, %s, %s, %s, %s, %s)")
            demande_clien = (id, nom, prenom, mail, tel, debut_contrat)

        try:
            cursor.execute(ajout_clien, demande_clien)
            cnx.commit()
        except Exception as e:
            logging.warning("problème d'insertion ", e)
        finally:
            cnx.close()
Ejemplo n.º 4
0
 def __init__(self, type_user, id):
     cnx = connexion()
     cursor = cnx.cursor()
     # Recuperation de la liste des nom de colone
     param = (
         "SELECT column_name FROM information_schema.columns WHERE table_name = '"
         + type_user + "' AND table_schema='Gestibank';")
     logging.debug(param)
     cursor.execute(param)
     res = cursor.fetchall()
     # verifie si l'objet existe dans la BD grace a son id,si non le cree
     if not User.trouver_id(type_user, id):
         logging.warning("L'ID N'A PAS été trouvé ")
         # for colone in res:
         #     self.__setattr__(colone[0].lower(), None)
         # self.id = id
         breakpoint()
     # cree un objet a partir des valeur de la BD
     else:
         for colone in res:
             command = ("Select " + colone[0] + " from " + type_user +
                        " where id = " + id)
             logging.debug(command)
             cursor.execute(command)
             value = cursor.fetchone()
             self.__setattr__(colone[0].lower(), value[0])
     cnx.close()
Ejemplo n.º 5
0
    def creation_compteban(self, id_client):
        if User.trouver_id('client', id_client) is True:
            cnx = connexion()
            cursor = cnx.cursor()
            id_compte = (random.randint(1000000000, 9999999999))
            type_compte = 'COURANT'
            date_creation =  str (date.today())
            rib = str(random.randint(1000000000, 9999999999))
            solde = 0.0

            ajout_clien = ("INSERT INTO `compte` (`id_compte`, `id_client`, `type_compte`, `rib`,"
                           " `solde`, `date_creation`) VALUES ( %s, %s, %s, %s, %s, %s)")
            demande_clien = (id_compte, id_client, type_compte, rib,solde, date_creation);

            logging.debug(ajout_clien + str(demande_clien))
            try:
                cursor.execute(ajout_clien, demande_clien)
                cnx.commit()
                logging.info("insertion réussi")
            except Exception as e:
                logging.warning("Erreur insertion", e)
            finally:
                cnx.close()
        else:
            logging.warning("Utilisateur n'existe pas ")
Ejemplo n.º 6
0
 def lister_demand_crea(self):
     cnx = connexion()
     cursor = cnx.cursor()
     cursor.execute("SELECT * FROM `demande_creacompte`")
     liste_obj = []
     for element in cursor:
         liste_obj.append(DemandCreaCompte(element))
     cnx.close()
     return liste_obj
Ejemplo n.º 7
0
 def __init__(self, id):
     super().__init__("Client", id)
     cnx = connexion()
     cursor = cnx.cursor()
     data = ("SELECT ID_compte FROM `compte` WHERE ID_client = " + id)
     logging.debug(data)
     cursor.execute(data)
     res = cursor.fetchall()
     self.liste_compte = []
     for colon in res:
         self.liste_compte.append(Compte(colon[0]))
Ejemplo n.º 8
0
 def login(self, id, password):
     cnx = connexion()
     cursor = cnx.cursor()
     command = ("SELECT TYPE_USER FROM login WHERE id='" + id +
                "' and password=PASSWORD('" + password + "')")
     logging.debug(command)
     cursor.execute(command)
     type_user = cursor.fetchone()
     logging.debug("login reussi")
     logging.debug(type_user)
     cnx.close()
     return type_user, id
Ejemplo n.º 9
0
 def suprimer_agent(self, id_Agent):
     if not self.trouver_id(table="client", where="id_agent", id=id_Agent):
         cnx = connexion()
         cursor = cnx.cursor()
         param = (" DELETE FROM `agent` WHERE `agent`.`ID` = '" + id_Agent +
                  "'")
         logging.debug(param)
         cursor.execute(param)
         cnx.commit()
         logging.warning("l'agent a ete supprimer")
     else:
         logging.warning("l'agent a toujours des client affecter")
Ejemplo n.º 10
0
 def create_dans_BD(self, type_user, id):
     if not User.trouver_id(type_user, id):
         cnx = connexion()
         cursor = cnx.cursor()
         param = "Insert INTO " + type_user + "(ID) VALUES('" + id + "')"
         logging.debug(param)
         try:
             cursor.execute(param)
             cnx.commit()
         except Exception as e:
             logging.warning("Problème avec la base:", e)
         finally:
             cnx.close()
Ejemplo n.º 11
0
 def trouver_id(self, type_user, id):
     cnx = connexion()
     cursor = cnx.cursor()
     param = ("SELECT id from " + type_user + " WHERE ID ='" + id + "'")
     logging.debug(param)
     cursor.execute(param)
     test = cursor.fetchone()
     cnx.close()
     try:
         test[0] == id
     except:
         return False
     else:
         return True
Ejemplo n.º 12
0
    def __init__(self, id_compte):

        cnx = connexion()
        cursor = cnx.cursor()
        param = ("SELECT `ID_compte`, `Type_compte`, `Date_creation`, `Rib`,`Solde`,`ID_client`"
                 " FROM `compte` WHERE ID_compte = " + str(id_compte))
        cursor.execute(param)
        element = cursor.fetchone()
        logging.debug(element)
        self.id_compte = element[0]
        self.type_compte = element[1]
        self.date_creation = element[2]
        self.rib = element[3]
        self.solde = element[4]
        self.id_client = element[5]
Ejemplo n.º 13
0
 def creation_compte_client(self):
     cnx = connexion()
     cursor = cnx.cursor()
     ajout_clien = (
         "INSERT INTO client (ID, NOM, PRENOM, MAIL, TEL, ADRESSE, JUSTIFICATIF, id_agent)"
         "VALUES ( %s, %s, %s, %s, %s, %s, %s, %s)")
     demande_clien = (self.id, self.nom, self.prenom, self.mail, self.tel,
                      self.adresse, self.justificatif, self.affect)
     try:
         cursor.execute(ajout_clien, demande_clien)
         cnx.commit()
     except Exception as e:
         logging.warning("problème d'insertion ", e)
     finally:
         cnx.close()
Ejemplo n.º 14
0
    def update(self, type_user, id, **kwargs):
        cnx = connexion()
        cursor = cnx.cursor()
        if kwargs is not None:
            for key, value in kwargs.items():
                try:
                    command = (" UPDATE `" + type_user + "` SET `" + key +
                               "` = '" + value + "' WHERE `client`.`ID` = '" +
                               id + "';")
                    logging.debug(command)

                    cursor.execute(command)
                    cnx.commit()
                except Exception as e:
                    logging.warning("N'existe pas dans la base", e)

        cnx.close()
Ejemplo n.º 15
0
    def affectation(self, agent):  # l'admin affect un client a un agent
        cnx = connexion()
        cursor = cnx.cursor()
        self.affect = agent
        try:
            affectation = ("UPDATE demande_creacompte SET affect = " +
                           self.affect + " WHERE  id =" + self.id)
            logging.debug(affectation)
            cursor.execute(affectation)
            cnx.commit()

        except:
            logging.warning("Problème d'affectation")
            return False
        else:
            return True
        finally:
            cnx.close()
Ejemplo n.º 16
0
    def flitre_compte(self):  # Retourne les demande de création de compte avec le id agent
        cnx = connexion()
        cursor = cnx.cursor()
        requette = "SELECT * FROM demande_creacompte WHERE affect = '" + self.id + "'"
        try:
            logging.debug(requette)
            cursor.execute(requette)
            liste_crea = cursor.fetchall()

            for demande in liste_crea:
                logging.debug(demande)
        except:
            logging.warning("Erreur base de donnée")
        else:
            liste_obj = []
            for element in liste_crea:
                liste_obj.append(Creation(element))
            return liste_obj
Ejemplo n.º 17
0
    def validation(self, valide):  # L'agent valide le client
        cnx = connexion()
        cursor = cnx.cursor()
        self.valid = valide
        try:
            validation = ("UPDATE demande_creacompte SET valide = " +
                          self.valid + " WHERE  id =" + self.id)
            logging.debug(validation)
            cursor.execute(validation)
            cnx.commit()

        except:
            logging.warning("Problème de  validation")
            return False
        else:
            return True
        finally:
            cnx.close()
Ejemplo n.º 18
0
    def modifMDP(self, oldMDP, newMDP):
        cnx = connexion()
        cnx.autocommit = True
        cursor = cnx.cursor()
        try:

            data = ("SELECT PASSWORD FROM login WHERE id = " + self.id +
                    " and Password = PASSWORD('" + oldMDP + "')")
            logging.debug(data)
            cursor.execute(data)
            changement = ("UPDATE login set Password = PASSWORD('" + newMDP +
                          "') where ID =" + self.id)

            logging.debug(changement)
            cursor.execute(changement)

            print("changement reussi")

        except Exception as e:
            logging.warning("Erreur de recherche ", e)
            logging.error(cursor.statement)
        cnx.close()
Ejemplo n.º 19
0
    def enregistrement(
        self
    ):  # Stocakge d'une demmande dans la base de donnee (table demande)
        cnx = connexion()
        cursor = cnx.cursor()

        try:
            insert_stmt = (
                "INSERT into demande_creation (nom,prenom,id,mail,telephone,adresse,justificatif)"
                "VALUES (%s ,%s, %s, %s,%s ,%s, %s)")
            data = [(self.nom, self.prenom, self.id, self.mail, self.tel,
                     self.adresse, self.justificatif)]
            cursor.execute(insert_stmt, data)
            cnx.commit()

        except:
            logging.warning("Problème a l'insertion")
            return False

        else:
            return True
        finally:
            cnx.close()